Manual:Pywikibot/i18n

This page is dedicated to help you understand i18n system in pywikibot.

For users

edit

I18n submodule is vital for running bots. It doesn't matter if you want to run pywikibot in an English-based wiki or not. If you want to install it you can run the following commands:

$ cd scripts
$ git clone https://gerrit.wikimedia.org/r/pywikibot/i18n.git
If you cloned pywikibot with --recursive option or downloaded nightly, i18n submodule is already there and there is no need to install anything.

With SVN submodule must be always configured and updated separately using:

$ cd scripts
$ svn co https://github.com/wikimedia/pywikibot-i18n/trunk i18n

I18n files are json files in scripts/i18n folder separated by language and script e.g. Persian i18n phrases related to category.py exist in:

scripts --> i18n --> category --> fa.json

Changing or adding i18n

edit

If you wish to change or add i18n for certain script in your language, use translatewiki.net and update your i18n submodule after one week or two. In order to update i18n submodule run the following commands:

$ cd scripts
$ cd i18n
$ git pull

or in root run:

$ git pull --recurse-submodules

If you can't wait, change it manually, but we don't recommend this since it may cause failure in next updates.

For developers

edit

I18n class is in i18n.py in pywikibot folder, the related documents can be found in the documentation. As an easy example:

>>> from pywikibot import i18n
>>> print(i18n.twtranslate('es', 'pywikibot-enter-new-text'))
Escribe el nuevo texto:
>>> print(i18n.twtranslate('arz', 'featured-good'))
بوت: %(page)s هي مقالة جيدة # Since arz translation doesn't exist, it returned ar i18n

You can give a site object instead of language code:

>>> import pywikibot
>>> print(pywikibot.i18n.twtranslate(pywikibot.Site('el'), 'featured-good'))
Ρομπότ: το %(page)s είναι καλό άρθρο


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.