This page is a translated version of the page Manual:Pywikibot/i18n and the translation is 94% complete.

本页面旨在帮助您了解pywikibot中的i18n 系统。

对于用户

I18n子模块对于运行机器人至关重要。您是否想在基于英语的wiki中运行pywikibot并不重要。 如果要安装它,可以运行以下命令:

$ cd scripts
$ git clone https://gerrit.wikimedia.org/r/pywikibot/i18n.git
如果您使用--recursive选项克隆pywikibot或每晚下载,i18n子模块已经存在,并且不需要安装任何东西。

必须始终使用以下命令单独配置和更新SVN子模块:

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

I18n文件是脚本/I18n文件夹中的json文件,以语言和脚本分隔。例如,与category.py相关的波斯语I18n短语存在于:

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

更改或添加i18n 如果您希望以某种语言更改或添加i18n,请使用translatewiki.net 并在一两周后更新您的i18n子模块。 要更新i18n子模块,请运行以下命令:

$ cd scripts
$ cd i18n
$ git pull

或者在root运行中:

$ git pull --recurse-submodules

如果您不能等待,请手动更改,但我们不建议这样做,因为它可能会导致下次更新失败。

对于开发者

I18n类在pywikibot文件夹中的i18n.py中,相关文档可以在the documentation中找到。 举个简单的例子:

>>> from pywikibot import i18n
>>> print(i18n.twtranslate('es', 'pywikibot-enter-new-text'))
Escribe el nuevo texto:
>>> print(i18n.twtranslate('arz', 'featured-good'))
بوت: %(page)s هي مقالة جيدة # 由于arz转换不存在,它返回ar i18n

您可以提供站点对象而不是语言代码:

>>> 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.