翻译项目

翻译组织

Weblate 将项目/组件的可翻译 VCS 内容组织成树状结构。

  • 底层对象是 项目配置,该项目配置应将所有翻译归在一起(例如,多个版本的应用程序翻译和/或随附的文档)。

  • 在上面的级别上,:ref:`component`(实际上是要翻译的组件),您定义要使用的 VCS 仓库以及要翻译的文件的掩码。

  • Component configuration 上方,有单独的翻译,当 VCS 仓库中出现翻译文件(与 Component configuration 中定义的掩码匹配)时,Weblate 会自动处理这些翻译。

Weblate 支持 Translate Toolkit 支持的多种翻译格式(双语和单语),请参阅 支持的文件格式

注解

您可以使用 Weblate internal URLs 共享克隆的 VCS 仓库。当您有许多共享同一 VCS 的组件时,强烈建议使用此功能。它提高了性能并减少了所需的磁盘空间。

添加翻译项目和组件

在 3.2 版更改: 已包含用于添加项目和组件的界面,您不再需要使用 Django 管理界面

在 3.4 版更改: 现在,添加组件的过程是多阶段的,可以自动发现大多数参数。

根据您的许可,可以创建新的翻译项目和组件。超级用户始终允许使用此功能,并且如果您的实例使用计费方式(例如 https://hosted.weblate.org/ 参见 账单),您还可以根据管理计费的用户帐户中的计划额度来创建计费方式。

您可以在单独的页面上查看当前的结算方案:

../_images/user-billing.png

您可以从此处开始创建项目,也可以使用导航栏中的菜单来填写翻译项目的基本信息以完成添加:

../_images/user-add-project.png

创建项目后,您将直接进入项目页面:

../_images/user-add-project-done.png

只需单击一次即可启动创建新翻译组件的操作。创建组件的过程是多阶段的,并自动检测大多数翻译参数。有几种创建组件的方法:

从版本控制

从远程版本控制仓库创建组件。

从现有组件

通过选择不同的文件为现有组件创建其他组件。

其他分支

仅针对不同分支,为现有组件创建其他组件。

上传翻译文件

如果您没有版本控制或不想将其与 Weblate 集成,则将翻译文件上传到 Weblate。您以后可以使用网络界面或 API 更新内容。

翻译文档

上传单个文档并进行翻译。

从头开始

创建空白翻译项目并手动添加字符串。

一旦有了现有的翻译组件,就可以使用同一仓库轻松地为其他文件或分支添加新的组件。

首先,您需要填写名称和仓库位置:

../_images/user-add-component-init.png

在下一页上,将显示已发现的可翻译资源的列表:

../_images/user-add-component-discovery.png

最后,您检查翻译组件信息并填写可选详细信息:

../_images/user-add-component.png

项目配置

创建一个翻译项目,然后在其中添加一个新的翻译组件。这个项目就像一个架子,里面堆放着真正的翻译。同一项目中的所有组件共享建议及其字典;翻译也将自动传播到单个项目中的所有组件(除非在组件配置中关闭),请参见 Memory Management

这些基本属性设置并通知翻译人员项目:

项目名称

详细的项目名称,用于显示项目名称。

Project slug

适用于 URL 的项目名称。

项目网站

译者可以在其中找到有关该项目的更多信息的 URL。

邮件列表

译者可以在其中讨论或评论翻译的邮件列表。

翻译说明

指向更多网站的 URL,为翻译人员提供了更详细的说明。

设置 Language-Team 头

Weblate 是否应管理 Language-Team 头(目前这是仅 GNU gettext 功能)。

使用共享的翻译记忆库

是否使用共享翻译记忆库,有关更多详细信息,请参见 共享翻译记忆库

贡献到共享的翻译记忆库

是否贡献到共享翻译记忆库,请参阅 共享翻译记忆库 以获取更多详细信息。

访问控制

配置每个项目的访问控制,请参阅 根据项目的访问控制 以获取更多详细信息。

可以通过 DEFAULT_ACCESS_CONTROL 更改默认值。

启用复查

Enable review workflow for translations, see 专门的审核者.

启用来源评论

Enable review workflow for source strings, see 源字符串复查.

启用 hooks

是否将未经身份验证的 通知钩子 用于此仓库。

源语言

所有组件中用于源字符串的语言。如果您要翻译的不是英语,请更改此选项。

提示

In case you are translating bilingual files from English, but want to be able to do fixes in the English translation as well, you might want to choose English (Developer) as a source language. To avoid conflict between name of the source language and existing translation.

For monolingual translations, you can use intermediate translation in this case, see 中间语言文件.

语言别名

Define language codes mapping when importing translations into Weblate. Use this when language codes are inconsistent in your repositories and you want to get a consistent view in Weblate.

The typical use case might be mapping American English to English: en_US:en

Multiple mappings to be separated by comma: en_GB:en,en_US:en

提示

The language codes are mapped when matching the translation files and the matches are case sensitive, so make sure you use the source language codes in same form as used in the filenames.

Component configuration

A component is a grouping of something for translation. You enter a VCS repository location and file mask for which files you want translated, and Weblate automatically fetches from this VCS, and finds all matching translatable files.

You can find some examples of typical configurations in the 支持的文件格式.

注解

It is recommended to keep translation components to a reasonable size - split the translation by anything that makes sense in your case (individual apps or addons, book chapters or websites).

Weblate easily handles translations with 10000s of strings, but it is harder to split work and coordinate among translators with such large translation components.

Should the language definition for a translation be missing, an empty definition is created and named as “cs_CZ (generated)”. You should adjust the definition and report this back to the Weblate authors, so that the missing languages can be included in next release.

The component contains all important parameters for working with the VCS, and for getting translations out of it:

组件名称

Verbose component name, used to display the component name.

Component slug

Component name suitable for URLs.

Component project

项目配置 where the component belongs.

版本控制系统

VCS to use, see 版本控制集成 for details.

源代码库

VCS repository used to pull changes.

参见

See Accessing repositories for more details on specifying URLs.

提示

This can either be a real VCS URL or weblate://project/component indicating that the repository should be shared with another component. See Weblate internal URLs for more details.

代码库推送 URL

Repository URL used for pushing. This setting is used only for Git and Mercurial and push support is turned off for these when this is empty.

参见

See Accessing repositories for more details on how to specify a repository URL and Pushing changes from Weblate for more details on pushing changes from Weblate.

代码库浏览器

URL of repository browser used to display source files (location of used messages). When empty, no such links will be generated. You can use Template markup.

For example on GitHub, use something like: https://github.com/WeblateOrg/hello/blob/{{branch}}/{{filename}}#L{{line}}

In case your paths are relative to different folder, you might want to strip leading directory by parentdir filter (see Template markup): https://github.com/WeblateOrg/hello/blob/{{branch}}/{{filename|parentdir}}#L{{line}}

已导出代码库 URL

URL where changes made by Weblate are exported. This is important when 持续本地化集成 is not used, or when there is a need to manually merge changes. You can use Git exporter to automate this for Git repositories.

仓库分支

Which branch to checkout from the VCS, and where to look for translations.

推送分支

Branch for pushing changes, leave empty to use 仓库分支.

注解

This is currently only supported for Git and GitHub, it is ignored for other VCS integrations.

文件掩码

要翻译的文件的掩码,包括路径。它应包含一个“*”替换语言代码(有关处理方式的信息,请参阅 Language definitions)。如果您的仓库包含多个翻译文件(例如,多个 gettext 域),则您需要为每个文件创建一个组件。

例如``po/.po`` 或 ``locale//LC_MESSAGES/django.po``。

如果文件名包含特殊字符(例如``[]``),则需要将这些特殊字符转义为 [[][]]

单语种译文模版语言文件

Base file containing string definitions for 单语言组件.

编辑译文模版文件

Whether to allow editing the base file for 单语言组件.

中间语言文件

Intermediate language file for 单语言组件. In most cases this is a translation file provided by developers and is used when creating actual source strings.

When set, the source translation is based on this file, but all others are based on 单语种译文模版语言文件. In case the string is not translated in source translation, translating to other languages is prohibited. This provides Quality gateway for the source strings.

新翻译的译文模版

Base file used to generate new translations, e.g. .pot file with gettext.

提示

In many monolingual formats Weblate starts with blank file by default. Use this in case you want to have all strings present with empty value when creating new translation.

文件格式

Translation file format, see also 支持的文件格式.

Source string bug report address

Email address used for reporting upstream bugs. This address will also receive notification about any source string comments made in Weblate.

允许同步翻译

You can turn off propagation of translations to this component from other components within same project. This really depends on what you are translating, sometimes it’s desirable to have make use of a translation more than once.

It’s usually a good idea to turn this off for monolingual translations, unless you are using the same IDs across the whole project.

Default value can be changed by DEFAULT_TRANSLATION_PROPAGATION.

启用建议

Whether translation suggestions are accepted for this component.

建议投票

Turns on votecasting for suggestions, see 建议投票.

自动接受建议

Automatically accept voted suggestions, see 建议投票.

翻译标记

Customization of quality checks and other Weblate behavior, see 定制行为.

强制检查

List of checks which can not be ignored, see 强制检查.

翻译许可证

License of the translation (does not need to be the same as the source code license).

贡献者协议

翻译此内容前需同意的协议。

添加新翻译

如何处理创建新语言的请求。可用选项:

联系维护者

用户可以选择所需的语言,项目维护者将收到有关该语言的通知。由他们决定是否向仓库添加(或不添加)语言。

显示翻译介绍

向用户显示的页面链接描述了开始新翻译的过程。如果需要更正式的流程(例如,在开始实际翻译之前组成人员团队),请使用此选项。

创建新语言文件

用户可以选择语言,然后 Weblate 会自动为其创建文件并开始翻译。

禁用添加新翻译

用户将无法选择开始新的翻译。

语言代码风格

Customize language code used to generate the filename for translations created by Weblate, see Adding new translations for more details.

合并方式

You can configure how updates from the upstream repository are handled. This might not be supported for some VCSs. See Merge or rebase for more details.

Default value can be changed by DEFAULT_MERGE_STYLE.

Commit, add, delete, merge and addon messages

Message used when committing a translation, see Template markup.

Default value can be changed by DEFAULT_ADD_MESSAGE, DEFAULT_ADDON_MESSAGE, DEFAULT_COMMIT_MESSAGE, DEFAULT_DELETE_MESSAGE, DEFAULT_MERGE_MESSAGE.

提交者姓名

Name of the committer used for Weblate commits, the author will always be the real translator. On some VCSs this might be not supported.

Default value can be changed by DEFAULT_COMMITER_NAME.

提交者邮箱

Email of committer used for Weblate commits, the author will always be the real translator. On some VCSs this might be not supported. The default value can be changed in DEFAULT_COMMITER_EMAIL.

提交时推送

Whether committed changes should be automatically pushed to the upstream repository. When enabled, the push is initiated once Weblate commits changes to its internal repository (see Lazy commits). To actually enable pushing Repository push URL has to be configured as well.

对变更进行提交的延时时间

Sets how old changes (in hours) are to get before they are committed by background task or commit_pending management command. All changes in a component are committed once there is at least one older than this period.

Default value can be changed by COMMIT_PENDING_HOURS.

出错时锁定

Enables locking the component on repository error (failed pull, push or merge). Locking in this situation avoids adding another conflict which would have to be resolved manually.

The component will be automatically unlocked once there are no repository errors left.

语言筛选

Regular expression used to filter the translation when scanning for filemask. This can be used to limit the list of languages managed by Weblate.

注解

You need to list language codes as they appear in the filename.

Some examples of filtering:

Filter description

正则表达式

Selected languages only

^(cs|de|es)$

Exclude languages

^(?!(it|fr)$).+$

Exclude non language files

^(?!(blank)$).+$

Include all files (default)

^[^.]+$

正则表达式变体

Regular expression used to determine the variants of a string, see String variants.

注解

Most of the fields can be edited by project owners or managers, in the Weblate interface.

优先权

高优先级的组件将最先提供给翻译者。

Restricted access

By default the component is visible to anybody who has access to the project, even if the person can not perform any changes in the component. This makes it easier to keep translation consistency within the project.

Enable this in case you want to grant access to this component explicitly - the project level permissions will not apply and you will have to specify component or component list level permission in order to grant access.

Default value can be changed by DEFAULT_RESTRICTED_COMPONENT.

提示

This applies to project managers as well - please make sure you will not loose access to the component after toggling the status.

Template markup

Weblate uses simple markup language in several places where text rendering is needed. It is based on The Django template language, so it can be quite powerful.

Currently it is used in:

There following variables are available in the component templates:

{{ language_code }}

语言代码

{{ language_name }}

语言名称

{{ component_name }}

组件名称

{{ component_slug }}

Component slug

{{ project_name }}

项目名称

{{ project_slug }}

Project slug

{{ url }}

Translation URL

{{ filename }}

翻译文件名

{{ stats }}

Translation stats, this has further attributes, examples below.

{{ stats.all }}

Total strings count

{{ stats.fuzzy }}

Count of strings needing review

{{ stats.fuzzy_percent }}

Percent of strings needing review

{{ stats.translated }}

Translated strings count

{{ stats.translated_percent }}

Translated strings percent

{{ stats.allchecks }}

Number of strings with failing checks

{{ stats.allchecks_percent }}

Percent of strings with failing checks

{{ author }}

Author of current commit, available only in the commit scope.

{{ addon_name }}

Name of currently executed addon, available only in the addon commit message.

The following variables are available in the repository browser or editor templates:

{{branch}}

current branch

{{line}}

line in file

{{filename}}

filename, you can also strip leading parts using the parentdir filter, for example {{filename|parentdir}}

You can combine them with filters:

{{ component|title }}

You can use conditions:

{% if stats.translated_percent > 80 %}Well translated!{% endif %}

There is additional tag available for replacing characters:

{% replace component "-" " " %}

You can combine it with filters:

{% replace component|capfirst "-" " " %}

There are also additional filter to manipulate with filenames:

Directory of a file: {{ filename|dirname }}
File without extension: {{ filename|stripext }}
File in parent dir: {{ filename|parentdir }}
It can be used multiple times:  {{ filename|parentdir|parentdir }}

…and other Django template features.

Importing speed

Fetching VCS repository and importing translations to Weblate can be a lengthy process, depending on size of your translations. Here are some tips:

Optimize configuration

The default configuration is useful for testing and debugging Weblate, while for a production setup, you should do some adjustments. Many of them have quite a big impact on performance. Please check Production setup for more details, especially:

Check resource limits

If you are importing huge translations or repositories, you might be hit by resource limitations of your server.

  • Check the amount of free memory, having translation files cached by the operating system will greatly improve performance.

  • Disk operations might be bottleneck if there is a lot of strings to process—the disk is pushed by both Weblate and the database.

  • Additional CPU cores might help improve performance of background tasks (see Background tasks using Celery).

Disable unneeded checks

Some quality checks can be quite expensive, and if not needed, can save you some time during import if omitted. See CHECK_LIST for info on configuration.

Automatic creation of components

In case your project has dozen of translation files (e.g. for different gettext domains, or parts of Android apps), you might want to import them automatically. This can either be achieved from the command line by using import_project or import_json, or by installing the 组件发现 addon.

To use the addon, you first need to create a component for one translation file (choose the one that is the least likely to be renamed or removed in future), and install the addon on this component.

For the management commands, you need to create a project which will contain all components and then run import_project or import_json.