Translation for developers/zh-cn
Beside the pure translation/zh-cn part of the work, the Kiwix source code needs to be synchronized with Translatewiki.
This synchronization with Translatewiki needs three types of operations:
- Add a string to Kiwix and Translatewiki, ie. introducing a dynamic string which will be replaced by the corresponding translation at the runtime.
- Update the Kiwix strings with the translations coming from Translatewiki.
- Add a new Translatewiki full translated language to Kiwix.
Requirements
You need a GNU/Linux Operating System. It is possible to do it in another operating system, but it is more complicated to get a working environment.
You need to have a few things in mind:
- Kiwix translation files are all in the "kiwix/chrome/locale" directory.
- There are two types of translation files to translate the User Interface (Have a look at the *.js and *.xul files in kiwix/chrome/content/main to understand how it works):
- "main.dtd" which provides translations for all *.xul files
- "main.properties" which provides translations for all *.js files.
- Translatewiki translations are imported separately in the Kiwix code repository once a week and we always need to synchronize those files with Kiwix code in both directions (KW->TW and TW -> KW).
警告:在修改Kiwix源代码之前,请在每个本地代码存储库中更新“git pull origin-master”。
Checkout the code and start Kiwix
Before starting to work on the integration of new strings in the Kiwix code, it's preferable to achieve to compile Kiwix:
- Get the unstable code
- Compile it
- Run it by going to the kiwix subdirectory and launching kiwix.
备注:如果你无法编译 Kiwix,或者没有 xulrunner 可用(例如在 Ubuntu Oneiric 及之后的版本中就是这种情况),你仍然可以启动 Kiwix 并获得一个界面,尽管应用程序无法正常工作,但例如对于操作 XUL 文件已经足够。在这种情况下,你需要做一些额外的步骤,比如在 kiwix/application.ini 中添加 "MaxVersion=42.*" 作为新行,然后在 "kiwix" 目录中使用该命令启动 Kiwix:"firefox -app application.ini"。
Add a string to the translations
Find a string to localize
Go through the *.xul and *.js files to find hardcoded strings (in English).
If you find one you need to find a string identifier (foobar for example), have a look to the already localized string to see how it should look like. The most important to know is that in the *.xul files, it should look like "&foobar;" and in the *.js like "getProperty('foobar')".
Translate it in the master language English
You will need to do that on two places. First in the "kiwix/chrome/locale/en/main/" main.dtd or main.properties files. In that way the Kiwix application knows what to display if the user interface language is English.
Update Translatewiki files
但是你也需要告诉 Translatewiki 将这个字符串添加到它必须提供的字符串列表中(供 Translatewiki 翻译者翻译)。为此,你需要检出 Kiwix 代码库的另一部分。请在本地 kiwix 代码目录之外运行以下控制台命令:
git pull origin master
你现在在电脑上有 translatewiki 的翻译文件。你需要做的只是更新 “en” 文件,它是 Translatewiki 的主语言文件。所以只需按照其他已插入字符串的示例添加你的新字符串,然后提交你的 “en” 文件。
Someone from Translatewiki check each week the "en" file for new strings and synchronized Translatewiki with this file if necessary.
Create stub translation of you new string for all languages
你需要做的最后一件事是为 Kiwix 的所有支持的用户界面语言创建新本地化字符串的占位翻译。如果你不这样做,Kiwix 将无法在非英语的语言环境下正常工作。
For that purpose you need to use the TW2PL.pl script (this is a perl script, so perl needs to be installed) like following (go in the translatewiki file directory):
./TW2KW.pl --path=/full/path/to/the/kiwix/code/directory --allLanguages=kw
Commit the new Kiwix translation files
Now, all the locale file in kiwix/chrome/locale should be updated and you should have a lot of (modified) files listed by typing:
git status kiwix/chrome/locale
After checking everything is OK, you can commit your modifications: ie. the kiwix/chrome/locale directory and the *.xul and/or *.js files you have modified.
Update Kiwix translations
另一个任务是使用来自 Translatewiki 的最新字符串更新已支持的 Kiwix 语言。首先需要了解的是,在远程子版本库中,Translatewiki 文件(位于 maintenance/translatewiki)每两周由 Translatewiki 贡献者更新一次。这意味着,你只需要更新本地库,然后像这样更新并提交 kiwix 代码翻译文件:
cd /full/path/to/the/kiwix/maintenance_tools/translatewiki
./TW2KW.pl --path=/full/path/to/the/kiwix/code/directory --allLanguages=kw
git commit /full/path/to/the/kiwix/code/directory/kiwix/chrome/locale
git push origin master
The full path should be the moulinkiwix directory, not the kiwix directory in it.
Add a new supported language to Kiwix
Kiwix 尝试只添加来自 Translatewiki 的 100% 翻译的语言。因此,经常会出现 “maintenance_tools/translatewiki” 目录中的语言比 “kiwix/kiwix/chrome/locale” 目录中的语言更多的情况。在这种情况下,这仅仅意味着 Translatewiki 的语言尚未集成到 Kiwix 代码库中。我们现在解释如何进行集成。
First of all you need to create the translation files in a new directory at "kiwix/kiwix/chrome/locale/your_language_iso_code" like this:
./TW2KW.pl --path=/full/path/to/your/kiwix/code/base/directory/ --language=your_language_iso_code
After that, you need go to the Kiwix source code directory in "kiwix/chrome" and edit with your preferred text editor the "chrome.manifest" and "chrome.manifest.prod" files. No explanation here, just do like for the already supported languages.
Next edit chrome/content/main/js/languages.js and here also add the new languages.
Now update CHANGELOG and make a notice about the addition of the new supported languages.
Add the new language directory and commit like this:
git add kiwix/chrome/locale/language_iso_code
git commit CHANGELOG kiwix/chrome/chrome.manifest kiwix/chrome/chrome.manifest.prod kiwix/chrome/locale/ kiwix/chrome/content/main/js/gui.js
git push origin master