TranslatorShellscript
Feel free to post improvements as well. In which languages it does not work at all? What kind of shell script are needed as well?
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.
Contents
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 "characters text" and a prior line the "characters name". Without saving the file with poEdit, the number of text-lines would be undefined.
poEdits Wrath
Anyhow, those changes introduced by poEdit should be undone prior sending the new po-File to your language maintainer. Especially, it must be undone prior to "diff" the new version against the old one. This may be done by executing the following:
msgattrib file.po > file.po1 mv file.po1 file.po
Now, if you
diff -u SVN.file.po file.po > file.po.diff
Your "diff" will only contain your changes and will look much nicer - your language maintainer will like you even more :). (see GettextForTranslators#FAQ)
Trailing Spaces
At the end of each translated "string", spaces should be avoided. Checking might be done using
- sed -n '/ "$/{N;s/\n$//p}' de.po
in a shell. (Checks whether there is a trailing space and the next line is empty.)
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 script with original and translated strings
Similar as above. A sed script to extract dialog and story parts in the form:
- [scenario]: id=<id>
- <original title>
- <translated title>
- [part]
- <original story part>
- <translated story part>
- <speaker>: <original dialog>
- <speaker>: <translated dialog>
- one-line version:
- sed -n 's/#\. \(\[scenario\]: id=.\+\)$/\n\n\1/p;s/#\. \(\[part\]\)$/\n\1/p;t msgid;s/#\. \[message\]: speaker=\(.\+\)$/\1/;t speaker;b;:speaker;H;n;s/#\. \[message\]: speaker=\(.\+\)$/, \1/;t speaker;x;s/$/:\t/;s/\n//g;x;t msgid;:msgid;s/msgid \(".*"\)/\1/;t nextmsgid;n;b msgid;:nextmsgid;H;n;/^".*"$/b nextmsgid;x;s/"\n"//g;s/\n//;p;s/".*"//;x;s/msgstr \(".*"\)/\1/;:nextmsgstr;H;n;/^".*"$/b nextmsgstr;x;s/"\n"//g;s/\n//;s/$/\n/;p' de.po
It works on unmodified po files as well.
Extracting a list of characters
Be aware, that you should be in the right directory. It contains *.cfg files for each campaign-scenario.
- cd <wesnoth-installpath>/data/campaigns/Northern_Rebirth/scenarios
- sed -n '/\[unit\]/,/\[\/unit\]/ba;/\[side\]/,/\[\/side\]/ba;b;:a s/^ *id *= *"\?\([^"]*\)"\?/\1/p' *.cfg | sort | uniq -c | sort -nr > ~/NRcharacterlist.txt
(Looks for id= keys in [side] and [unit] tags and extracts the value then sorts them by number of occurrences.)
You can leave off the "-c | sort -nr" part if you don't care about the number of occurrences.
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. Hence, improvements might be a very good idea - If anybody has suggestions, feel free to contact me or just post it here. Or even realize them on a higher level - why not writing a script to transform it in TEX - per aspera ad astra :).