Manual:Pywikibot/i18n conversion

Here's how to spread TW integration through the scripts/ directory.

As you will notice, there is now a i18n/ directory inside the scripts/ directory. This directory contains all files exported from TranslateWiki. The script name defines which TW keys are defined in the file, so i18n/category.py contains category-* (category-was-moved, category-also-in, etc.). These are the translations that before were in scripts/category.py.

Adapting scripts to TranslateWiki consists of four parts:
 * Defining TW keys for translations
 * Reading in translations and outputting them into the TW format
 * Removing translations from script file
 * Adding  and adapting all/most   entries with.

Defining TW keys
To use isbn.py as an example. There is only one message (only showing German and English):

For TW, we define this message as isbn-formatting.

Sometimes pywikibot.translate is used for site- or language-specific configuration. Don't move those to TranslateWiki files (yet).

Reading in translations and outputting them into the TW format
Although it is possible to do the ISBN example by hand, I'll use a script that can easily be adapted for a larger number of messages. Don't forget to  your virtualenv! The script is available at http://pastebin.com/u2XrKt5b (too long to paste here).

For other scripts, you have to adapt at least lines 2, 6 and 12. Line 12 has a list of tuples (old dict, TranslateWiki key). If the messages have (one or more) parameters, you should change them to named parameters, so translators can move them around in the message. See lines 15 and 16 for an example of how to do this.

Running this script gives you a new file, i18n/isbn.py.

Test the translation:

hurrah!

Removing translations from the script file
Use a sledgehammer, jackhammer, or scalpel. Whatever works for you. In the case of isbn.py, lines 49 to 61.

Adapting all/most pywikibot.translate entries
Search for pywikibot.translate. Change the following: to or

With 'tw-key-for-msg' referring to the tw key you thought up for msg, and 'param_1' and 'param_2' (the dictionary keys) referring to the named parameters you introduced in step 2.

For isbn.py, this is simpler:

Congratulations! You have adapted a script to use TranslateWiki translations!

Of course, before committing, test the script:

And, as a last step, commit the script (and the translations!) to the svn repository: Special:Code/pywikipedia/8838

Good luck adapting scripts!