TranslatorShellscript

From The Battle for Wesnoth Wiki
Revision as of 15:20, 22 March 2009 by Crommy (talk | contribs) (Comments)

Feel free to post improvements as well. In which languages it does not work at all? What kind of shell script would are needed as well?

Or even realize them on a higher level - why not writing a script to transform it in TEX - per aspera ad astra :).

Thanks to the programmer(s) that included the "speaker" in the comments of the po-files (Ivanovic?)! Those are definitely helpful and make this approach possible.

First of all

Prior to use the shell scripts, the po-File needs to be opened and saved with poEdit. The reason is, that then the texts are saved in separated lines without interfering /n's. As result, a normal entry consists of 4 lines, where one line contains the "charaxters text" and a prior line the "charactors name". Without saving the file with poEdit, the number of text-lines would be undefined.

Extracting a target language script

For proof-reading of a campaign it might be much easier to print it out in a more "scriptlike" format (<charactername>: <text>) (target language only), e.g. to read it in a bus, a train or in a car.

I load this textfile into a editor to print it in two columns with the name of the "speaker" intended (like in script book).

>cat ./de.po | grep -v "msgid \"" | grep -v "#: data" | sed "s/\[message\]: speaker//g" | sed "s/#. =//g" | sed "s/msgstr/:/g" |grep -v ": \"\"" | sed ':;s/\n:/:/;N;T' | sed ':;s/\n\n/\n/;N;T'| sed "s/#. \[scenario\]/\n#. \[scenario\]/g" > target-language-script.txt

Extracting an English script

For proof-reading of a campaign it might be much easier to print it out in a more "scriptlike" format (<charactername>: <text>) (english only), e.g. to read it in a bus. This one is even more preliminary than the one before. It still contains some target language parts.

>cat de.po | grep -v "msgstr \"" | grep -v "#: data" | sed "s/\[message\]: speaker//g" | sed "s/#. =//g" | sed "s/msgid/:/g" |grep -v ": \"\"" | sed ':;s/\n:/:/;N;T' | sed ':;s/\n\n/\n/;N;T'| sed "s/#. \[scenario\]/\n#. \[scenario\]/g" > english.txt

Extracting a list of characters

using the command line

Be aware, that you should be in the right directory. It contains *.cfg files for each campaign-scenaio.

> cd <wesnoth-installpath>/data/campaigns/Northern_Rebirth/scenarios
>cat *.cfg | grep "description=" | grep -v "_" | sed 's/^[ \t]*//;s/[ \t]*$//' | sort |uniq -c | sort -nr > ~/NRcharacterlist.txt

using a shell script

save the following as script, e.g. named "extChar.sh". Use it within the correct directory (see above) with the target file as option. Use "chmod" to make it executable.


#bash
# extract characters/personnames from wesnoth cfg files
cat *.cfg | grep "description=" | grep -v "_" | sed 's/^[ \t]*//;s/[ \t]*$//' | sort |uniq -c | sort -nr > ~/Desktop/$1

step 2 - if you want to have the characters list only

>cat NRcharacterlist.txt | cut -d '=' -f 2

Translating without knowing English?

(This was copied from the Wesnoth translation forum, a thread and an brilliant idea from User:Viliam http://www.wesnoth.org/forum/viewtopic.php?f=7&t=8817)

Have you found someone willing to translate Wesnoth to a language X (or willing to help you translating to your language), but then you found that the person does not speak English? This is no longer a problem!


My solution is a Perl script that will enrich your PO file with translations to other language(s), inserted as comments to the English phrases. When you work with "poEdit" application and click on the phrase, you will see translations in other language(s) in the comment window; so you can translate the phrase without a good knowledge of English, or you can have an advantage of using translation to language similar to your one.

You can immediately use the compiled MO files in game, because the PO file remains an "English to language X" translation. Only comments are changed, nothing else.


Examples:

I have a Slovak translation "sk.po", and would like to use a Czech translation as help:

multi_po.pl sk.po --add cs.po CS > sk_multi.po

In file "sk_multi.po" there is for every phrase added corresponding Czech translation from "cs.po" file, labeled as "CS". (My original comments in "sk.po" file are there, too.)

Before sending to translation maintainers, I remove unnecessary comments:

multi_po.pl sk_multi.po --remove > sk.po

The Czech translations are removed. (My original comments remained.)

It is possible to add more languages to one PO file. To use newer version of translation, you must remove the translations, and add them again. Your comments will remain (unless you use "{ ... }" as substring in them).


If someone finds this helpful, please report to me any bugs found. (That is... be careful and backup your PO files. This is a program written today, not much tested yet.)

http://www.wesnoth.org/forum/download/file.php?id=5872


Comments

Disclaimer: This scripts are far away from "flawless". Anyhow, try it, like it, use it; dislike it, improve it :).

And, yes, I know, its programming (the ones I did) is pathetic :). And, yes, more knowledge about WML would definitely improve it. Or a higher frustration threshold... :). Or the accuracy, a real programmer would have (and test it with more than one po-file in one language only). Hence, improvements might be a very good idea - If anybody has suggestions, feel free to contact me.