ToolTranslate

From Meta, a Wikimedia project coordination wiki
This page is a translated version of the page ToolTranslate and the translation is 80% complete.
ToolTranslate界面

此为ToolTranslate工具的手册。敬请翻译它!

目的

Toolforge平台上的许多工具欠缺对界面的翻译,只提供一种界面语言(通常是英语)。即便是支持多语言界面的工具,很多也是以笨拙的方法实现语言添加和翻译。ToolTranslate为社区及工具提供了集中式、用户友好的翻译方法。用它实现翻译支持的工具只需修改一次界面,即可享用动态而非静态的翻译文本。最早的博客文章

翻译

  1. 打开此工具
  2. 如果还没有,授权此工具以验证您的身份
  3. 从顶部的下拉框或首页的列表选择要翻译的工具
  4. 选择或添加要翻译的目标语言
  5. 双击想新增或改善翻译的单元格
  6. 输入新的译文。可以在其中使用HTML,但不能使用JavaScript代码。工具可能建议您使用另一个有相同键名的译文,点击即可填入作为译文的基础。
  7. 点击确定,翻译完成!除浏览器缓存问题外,您提供的翻译应在下次加载网页时显现在相应工具中。

資源

技术信息

译文在Toolforge上的一个数据库中储存。译文的旧版本会保留,且所有译文有记录提交者。提供有一个“最近更改”功能。

为简化对译文数据的访问,所有翻译也在JSON文件中储存,每次更改时都会更新JSON文件。以"demotool1"为例:

  • toolinfo.json,包含此工具信息的JSON文件
  • en.json,包括此工具英文译本的JSON文件。其他语言以各自的语言代码提供。

还有一个JSON文件包含所有有效语言。

資料庫

源文本数据存储在Toolforge上tools-db的s53069__tooltranslate_p数据库(mysql --defaults-file=~/replica.my.cnf -h tools-db s53069__tooltranslate_p)。需要时也可从那里获取数据。 含有如下表:

  • tool
    • id | name | label | url | owner
  • translation
    • id | tool_id | language | key | json | user | timestamp | current

HTML/JS用法

PHP用法

There is a PHP class that you can include on Toolforge, like so:

require_once ( "/data/project/tooltranslate/public_html/tt.php") ;

然后您可以实例化类:

$tt = new ToolTranslation ( array ( 'tool' => 'your_tool_key' , 'language' => 'de' , 'fallback' => 'en' , 'highlight_missing' => true ) ) ; // 除“tool”外的所有内容都是可选的

直接使用

There are two ways of getting interface translations in PHP. One is directly getting a translated string

print "<p>" . $tt->t('translation_key') . "</p>" ;

But this has the disadvantage that the translation cannot be changed without reloading the page.

通过JS使用

You can instead add HTML "translation tags" (see above), and have the class add the necessary JS invocation. Another advantage is that the PHP class does not need to load any translation files if you never use the "direct" translation above. To use HTML/JS translation, the <head> section of your pages' HTML needs to contain

<script src="https://tools-static.wmflabs.org/tooltranslate/tt.js">

(您还需要jQuery) 生成页面时,不要使用上文的写法,而是写:

print "<p tt='translation_key'></p>" ;

Somewhere in the output (maybe towards the end), you will need to add the invocation code:

print $tt->getJS() ;

This will initialize the required JS, reproducing the parameters used in the PHP instance (fallback language etc.). If you want a "translation dropdown", add a wrapper element in your HTML code

<div id='tooltranslate_wrapper'></div>

然后将“jQuery访问器”作为getJS方法调用的一个参数:

print $tt->getJS('#tooltranslate_wrapper') ;

参考此工具了解实际如何运作。