Manual:Pywikibot/i18n
![]() |
Pywikibot |
---|
This page is dedicated to help you understand i18n system in pywikibot.
For users[edit | edit source]
I18n submodule is vital for running bots, It doesn't matter if you want to run pywikibot in a English-based wiki or not. In core i18n files exist in scripts folder and in compat they can be found in root folder (i18n folder). So If you want to install it you should do:
cd scripts #This step is necessary for core, don't do it in compat git clone https://gerrit.wikimedia.org/r/pywikibot/i18n.git
Template:Note/en If you cloned pywikibot with --recursive
option or you downloaded nightly, i18n submodule is already there and no need to install anything.
I18n files are json files in 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 | edit source]
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 you need to command:
cd scripts #Don't do in compat cd i18n git pull
or in root run:
git pullall
If you can't wait change it manually but we don't recommend since it may cause failure in next updates.
For developers[edit | edit source]
I18n class is in i18n.py in pywikibot folder (both core and compat), the related documents can be found in the files. 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 είναι καλό άρθρο