Manual:Pywikibot/i18n

From MediaWiki.org
Jump to: navigation, search

Other languages:
Deutsch • ‎Ελληνικά • ‎English • ‎español • ‎français • ‎日本語 • ‎polski • ‎slovenščina

This page is dedicated to help you understand i18nLocalisation 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

Note Note: If you cloned pywikibot with --recursive option or downloaded nightly, i18n submodule is already there and there is no need to install anything.

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.nettranslatewiki.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.twntranslate('es', 'pywikibot-enter-new-text')
Escribe el nuevo texto:
>>> print i18n.twntranslate('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.twntranslate(pywikibot.Site('el'), 'featured-good')
Ρομπότ: το %(page)s είναι καλό άρθρο