Help:Extension:Translate/Translation memories/zh

The Translate extension translation memory supports multiple backends. The available backends are database, Solr and ElasticSearch. This page helps you install the best one for you and explains their specifications in deeper detail.

Unlike other translation aids, for instance external machine translation services, the translation memory is constantly updated by new translations in your wiki. Advanced search across translations is also available at Special:SearchTranslations if you choose Solr or ElasticSearch.

Comparison
The database backend is used by default: it has no dependencies and doesn't need configuration. The database backend can't be shared among multiple wikis and it does not scale to large amounts of translated content. Hence we also support Solr and ElasticSearch backends. It is also possible to use another wiki's translation memory via their web API if open. Unlike the others, remote backends are not updated with translations from the current wiki.

ElasticSearch 后端
ElasticSearch is relatively easy to set up. If it is not available in your distribution packages, you can get it from their website. You will also need to get the Elastica extension. Finally, please see for specific configuration needed by Translate.

The bootstrap script will create necessary schemas. If you are using ElasticSearch backend with multiple wikis, they will share the translation memory by default, unless you set the index parameter in the configuration.

When upgrading to the next major version of elasticsearch (e.g. upgrading from 2.x to 5.x), it is highly recommended to read the release notes and the documentation regarding the upgrade process. Elastic offers a migration plugin that may help you to prepare your system before installing the next version. Follow these steps carefully otherwise elasticsearch may refuse to upgrade and you may end up in a delicate situation where you cannot rollback to the previous version.

Once the next major version is installed it's probable that the next time you run  it fails. This is because elasticsearch will perform an internal migration progress that may create an incompatible mapping with the one  wants to update. You have to use the  flag to force a full rebuild of the index.

As a rule of thumb it is recommended to run  with the   flag after major upgrades. You will ensure that your indices are always created with the current elasticsearch version which is a requirement for major upgrades.

Solr backend
Here are the general quick steps for installing and configuring Solr for TTMServer. You should adapt them to your situation.

To use Solr backend you also need Solarium library. The easiest way is to  install the Solarium extension. See the example configuration for Solr backend in the configuration section of this page. You can pass extra configuration to Solarium via the  key as done for example  in the.

安装
After putting the requirements in place, installation requires you to tweak the configuration and then execute the bootstrap.

配置
包含翻译记忆的所有翻译辅助功能都通过  设置来配置. TTMServer 配置示例：

The primary translation memory backend must use the key. The primary backend receives translation updates and is used by Special:SearchTranslations.

Example configuration of TTMServers:

可能的键值为：

目前只支持 MySQL 数据库.

Bootstrap
When you have chosen Solr or ElasticSearch and set up the requirements and configuration, run  to bootstrap the translation memory. Bootstrapping is also required when changing translation memory backend. If you are using a shared translation memory backend for multiple wikis, you'll need to bootstrap each of them separately.

Sites with lots of translations should consider using multiple threads with the  parameter to speed up the process. The time depends heavily on how complete the message group completion stats are (incomplete ones will be calculated during the bootstrap). New translations are automatically added by a hook. New sources (message definitions) are added when the first translation is created.

Bootstrap does the following things, which don't happen otherwise:
 * adding and updating the translation memory schema;
 * populating the translation memory with existing translations;
 * cleaning up unused translation entries by emptying and re-populating the translation memory.

When the translation of a message is updated, the previous translation is removed from the translation memory. However, when translations are updated against a new definition, a new entry is added but the old definition and its old translations remain in the database until purged. When a message changes definition or is removed from all message groups, nothing happens immediately. Saving a translation as fuzzy does not add a new translation nor delete an old one in the translation memory.

TTMServer API
如果您想实现自己的 TTMServer 数据库，请看详细说明.

查询参数：

您的服务必须接受下列参数：

您的服务必须提供对象数组中含有键  的 JSON 对象. 这些对象必须包含下列数据：

例如：


 * 链接：http://translatewiki.net/w/api.php?action=ttmserver&sourcelanguage=en&targetlanguage=fi&text=january&format=jsonfm
 * 应答：

数据库后端
后端包含了三个表： 、 和  ，分别对应于源、目标和完整的文本. 您可以在  中看到表格的定义. 源包含了所有信息组定义. Even though usually they are always in the same language, say, English, the language of the text is also stored for the rare cases this is not true.

每个条目都有唯一的 ID 和两个附加字段：长度和上下文. 查询时使用长度作为首个过滤器，这样就无需把要搜索的文本和数据库中每个条目进行比较. 上下文中保存了文本来源的页面标题，例如“MediaWiki:Jan/en”. 根据该信息，我们可以把建议链接到“MediaWiki:Jan/de”，这样有助于译者快速修复问题或确定使用哪个译文.

第二个过滤器来自全文索引. 它的定义与 ad hoc 算法混合. 首先通过 MediaWiki 的  把文本分割为片段（词）. 如果有足够的片段，我们主要去除所有非单词字母的那些内容来常态化. 接着获取开头的十个唯一单词，必须至少五个字节长（英文中的五个字母，对于多字节字符则更少字数）. 然后把这些词保存在全文索引中供将来过滤更长的字符串.

过滤出候选列表后，则从目标表中获取匹配的目标. 然后使用编辑距离算法进行最后的过滤和排序. 定义如下：


 * E : 编辑距离
 * S : 用于搜索建议的文本
 * Tc : 建议文本
 * To : 译文 Tc 的原始文本

通过 E/min(length(Tc),length(To)) 计算 Tc 建议的质量. 我们使用 PHP 内置的 levenshtein 函数，但当某个字符串长于 255 字节时，则使用 PHP 实现的 levenshtein 算法. 尚未测试内置的 levenshtein 是否能正确处理多字节字符. 当源语言不是英文时，这可能是另一个问题（全文索引和分割时）.

Solr 后端
Solr Solr search platform backend works similar to the database backend, except that it uses a dedicated search engine for increased speed. The results are by default ranked with the levenshtein algorithm on the Solr side, but other available string matching algorithms can also be used, like ngram matching for example.

在 Solr 中没有表格，这里使用含字段的文档代替. 下面是一个示例文档：

每个译文有自己的文档，而每个信息文件也有一个. 要实际获取建议，首先对源语言的所有文档根据字符串相似度算法分类进行搜索，然后再次查询获取这些信息的译文.

我们使用大量的钩子以保持翻译记忆数据库的实时更新. 如果用户一个接一个翻译了类似的信息，则之前的译文会在翻译后面的信息时显示为建议（最好的情况下）.

New translation (if not fuzzy)
 * 1) Create document

Updated translation (if not fuzzy)
 * 1) Delete wiki:X language:Y message:Z
 * 2) Create document

Updated message definition All existing documents for the message stay around because globalid is different.
 * 1) Create new document

Translation is fuzzied
 * 1) Delete wiki:X language:Y message:Z

Messages changes group membership
 * 1) Delete wiki:Z message:Z
 * 2) Create document (for all languages)

Message goes out of use Any further changes to definitions or translations are not updated to TM.
 * 1) Delete wiki:Z message:Z
 * 2) Create document (for all languages)

Translation memory query
 * 1) Collect similar messages with strdist("message definition",content)
 * 2) Collect translation with globalid:[A,B,C]

Search query Can be narrowed further by facets on language or group field.
 * 1) Find all matches with text:"search query"

Identifier fields Field  uniquely identifies the translation or message definition by combining the following fields: The used format is.
 * wiki identifier (MediaWiki database id)
 * message identifier (Title of the base page)
 * message version identifier (Revision id of the message definition page)
 * message language

In addition we have separate fields for wiki id, message id and language to make the delete queries listed above possible.