<a id="memory"></a>

<a id="translation-memory"></a>

# 翻译记忆库

Weblate 带有内建的翻译记忆库，其组成部分为：

* 手动导入翻译记忆库（请参见 [用户界面](#memory-user)）。
* 自动存储 Weblate 中进行的翻译（取决于 [翻译记忆库的作用域](#memory-scopes)）。
* 自动导入以前的翻译。

可以用几种方法将翻译记忆库中的内容应用于字符串：

* 用户可以在编辑字符串时从 [自动建议](https://docs.weblate.org/zh-cn/latest/user/translating.md#machine-translation) 标签页接受建议。
* 可以从 操作 菜单使用 [自动翻译](https://docs.weblate.org/zh-cn/latest/user/translating.md#auto-translation) 处理所选的字符串。
* [自动翻译](https://docs.weblate.org/zh-cn/latest/admin/addons.md#addon-weblate-autotranslate-autotranslate) 附加组件可以自动将更改应用于新的和现有的字符串。

对于安装提示，请参见 [Weblate 翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/machine.md#mt-weblate-translation-memory)，它默认是打开的。

<a id="memory-scopes"></a>

## 翻译记忆库的作用域

翻译记忆库的作用域确保不同项目和用户的隐私。也可以用来共享译文。

#### NOTE
从旧版 Weblate 升级时，现有的翻译记忆条目会通过周期性 Celery 后台任务转换为作用域。在回填任务完成前，现有条目在译文建议与记忆管理视图中会暂时不可用。升级后请保持 Celery 运行，以便该周期性任务可以启动或继续迁移。站点管理员可在 管理 > 性能报告 中监控回填与重复条目合并进度。

### 导入翻译记忆库

使用 [`import_memory`](https://docs.weblate.org/zh-cn/latest/admin/management.md#weblate-admin-import_memory) 命令导入任意翻译记忆库数据，使记忆的内容可用于所有的用户和项目。

### 以用户为基准的翻译记忆库

在每个单独用户的个人翻译记忆库中自动存储用户的翻译。

基于 [自动清理翻译记忆库](#autoclean-tm) 配置自动调整新用户的默认值。如果默认清理开启，则默认禁用这个放置重新引入不一致的译文。

### 以项目为基准的翻译记忆库

项目内的所有翻译都自动存储在项目翻译记忆库中，这个翻译记忆库只在项目内可用。

归属至现有受限组件的条目，仅对拥有该组件访问权限的用户可见。通过 REST API 下载或访问项目记忆库时同样遵循此规则。

无法归属到当前组件的旧条目将沿用项目访问规则。当组件路径发生变更或是组件已被删除时会出现这种情况。

### 工作区翻译记忆库

同一工作区内的项目可共享翻译记忆库，无需开启全局共享翻译记忆库。工作区翻译记忆库需要同时在工作区设置以及各个项目的工作流设置中启用。

归属至现有受限组件的条目，仅对拥有该组件访问权限的用户可见，即使用户可以访问该工作区内其他项目也不例外。无归属的旧条目将采用工作区访问规则。

#### SEE ALSO
* [使用工作区的翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/workspaces.md#workspace-use-workspace-tm)
* [给工作区翻译记忆库作贡献](https://docs.weblate.org/zh-cn/latest/admin/workspaces.md#workspace-contribute-workspace-tm)
* [使用工作区的翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-use-workspace-tm)
* [给工作区翻译记忆库作贡献](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-contribute-workspace-tm)

<a id="shared-tm"></a>

### 共享翻译记忆库

开启翻译记忆库共享的项目内的所有翻译都存储在共享的翻译记忆库中，可用于所有项目。关闭对共享翻译记忆库的贡献会阻止之前贡献的自动条目被用作共享的建议。

Contributing to shared translation memory is an explicit publication action.
Project access control does not restrict the contributed source strings,
translations, or project and component origin. This also applies to
Private and Custom projects. Authenticated users can
enumerate the shared pool using the [memory API](https://docs.weblate.org/zh-cn/latest/api.md#api-memory) without
knowing a source string in advance.

受限部件不向共享的翻译记忆库贡献新条目。

This exclusion applies to shared translation memory entries. Saved automatic
translation add-ons and automation workflows can use eligible
restricted components directly as sources under add-on management authority.
See [附加组件](https://docs.weblate.org/zh-cn/latest/admin/addons.md#addons) and [工作流定义](https://docs.weblate.org/zh-cn/latest/admin/automation.md#automation-workflows).

On Hosted Weblate, a project with restricted components can not enable shared
translation memory, and a component can not be restricted while its project
uses shared translation memory.

Unattributed legacy entries which are already in shared translation memory use
the shared translation memory access rules.

对于分享的 Weblate 安装，请仔细考虑是否打开这个特性，因为可能导致严重的影响：

* 翻译可以被任何人使用。
* 这会导致泄露秘密信息。
* 请确保你共享的译文质量上乘。

#### SEE ALSO
* [贡献到共享的翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-contribute-shared-tm)
* [使用共享的翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-use-shared-tm)

<a id="memory-status"></a>

## 翻译记忆库状态

#### Versionadded
Added in version 5.13.

翻译记忆库条目可以有两种不同状态：**活跃** 和 **未提交**。未提交条目包含在建议中，但适用质量惩罚。根据配置的分数阈值，惩罚甚至可以排除来自建议和自动翻译的精确匹配。从翻译记忆库文件导入的条目被存储为活跃状态。如启用了 [自动清理翻译记忆库](#autoclean-tm)，当译文状态变为活跃时匹配的未提交条目被删除。

<a id="autoclean-tm"></a>

## 自动清理翻译记忆库

#### Versionadded
Added in version 5.13.

对项目启用后，当翻译生效时 Weblate 替换旧的自动生成的翻译记忆库条目：

* 启用 [启用审核](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-translation-review) 时，清理在批准翻译时发生。
* 如果没有审校，译文一转为已翻译状态就会被清理。

对于同一源字符串、部件、上下文和源/目标语言对，Weblate 从翻译记忆库中删除匹配的非文件条目，包括目标文本不同的条目。这应用于个人、项目和共享的翻译记忆库作用域。然后当前翻译被在为此更改激活的作用域中再次存储为活跃条目。

不自动清理从外部翻译记忆库导入的条目。保留上下文不同的条目。

在 Docker 容器中可使用 [`WEBLATE_DEFAULT_AUTOCLEAN_TM`](https://docs.weblate.org/zh-cn/latest/admin/install/docker.md#envvar-WEBLATE_DEFAULT_AUTOCLEAN_TM) 对此进行配置。

#### NOTE
开启自动清理还会将新用户个人资料的默认值更改为不录入个人翻译记忆库。这防止重新引入打算要清理的不一致的译文。

#### SEE ALSO
[自动清理翻译记忆库](https://docs.weblate.org/zh-cn/latest/admin/projects.md#project-autoclean-tm)

## 管理翻译记忆库

<a id="memory-user"></a>

### 用户界面

可以从 Weblate 用户界面的几个地方管理翻译记忆库：

* 打开用户菜单，选择 翻译记忆库 管理你的个人翻译记忆库。
* 打开项目，从项目菜单选择 翻译记忆库 来管理项目的翻译记忆库。
* 打开工作区，选择 操作 ↓ 翻译记忆库 管理该工作区自动创建的翻译记忆库。需要编辑该工作区。
* 打开 管理，选择 翻译记忆库 管理整个 Weblate 实例的已上传的翻译记忆库。

翻译记忆库页面显示所选作用域的条目数。根据作用域不同，页面还按照来源、部件或语言对列出条目。所列条目可下载为 JSON 或 TMX。有所需权限的用户可以删除条目，项目视图可以从当前翻译重建整个项目或单独部件的翻译记忆库。

Removing a component preserves its automatically created translation memory by
default. This preserves the behavior of Weblate versions which did not track
the source component of translation-memory entries, and avoids unexpected data
loss when a component is removed or replaced.

Because the component access rule no longer exists after removal, retained
entries use the access rules of their remaining translation-memory scope. For
a restricted component, this can make retained entries visible to other members
of its project or workspace. Select
Delete translation memory created from this component in the
removal form when the entries should be removed with the component, especially
when its restricted content must remain unavailable after removal. Category
removal offers the equivalent option for every component in the category and
its nested categories.

The deletion option removes attributed entries and legacy entries matching the
current component path. It does not infer paths used before a component or
category rename or move. Such unmatched entries can be deleted by origin in the
project or workspace translation memory management, or using the REST API. The
REST API accepts the `delete_memory` boolean in the request body or query
string for component and category removal. Personal and uploaded entries are
preserved regardless of this option.

项目视图还显示项目是否启用了共享的翻译记忆库和自动清理翻译记忆库，当用户可以编辑项目时会显示到项目工作流设置的链接。

The workspace view can rebuild all currently contributing projects or an
individual contributing component. It manages workspace-scoped automatic
entries only. Translation-memory files cannot be uploaded into a workspace
scope.

可以在相同页面导入翻译记忆库。上传的文件在请求期间被处理，存储为活跃状态，并添加到所选作用域：

* 个人上传在个人翻译记忆库中。
* 项目上传在所选项目的翻译记忆库中。
* 管理性质的上传作为上传的共享条目对整个实例可用。

Imports enforce [`TRANSLATION_MAX_SIZE`](https://docs.weblate.org/zh-cn/latest/admin/config.md#std-setting-TRANSLATION_MAX_SIZE) before parsing and accept at most
100,000 entries per file. JSON entries are counted before schema validation.
For TMX, both translation units and source-target pairs count toward the limit,
including repeated or empty entries and multiple target languages. Limit failures
are rejected before any entries are written. Accepted imports write database
changes in batches of 1,000 entries.

Browser uploads must also satisfy [`TRANSLATION_UPLOAD_MAX_SIZE`](https://docs.weblate.org/zh-cn/latest/admin/config.md#std-setting-TRANSLATION_UPLOAD_MAX_SIZE) and
share the per-user [`RATELIMIT_UPLOAD_ATTEMPTS`](https://docs.weblate.org/zh-cn/latest/admin/config.md#std-setting-RATELIMIT_UPLOAD_ATTEMPTS) budget with translation
uploads. Superusers are exempt from rate limiting. The [`import_memory`](https://docs.weblate.org/zh-cn/latest/admin/management.md#weblate-admin-import_memory)
command enforces the same parsing and entry-count limits without HTTP rate
limiting. Split larger memories into smaller files before importing them.

#### HINT
可以将多种格式的翻译记忆库导入 Weblate，提供了 TMX 格式方便与其他工具进行互操作。所有支持的格式如下为 TMX、JSON、XLIFF、PO、CSV。

如果 XLIFF、PO 或 CSV 文件本身未提供语言信息，那么上传这些类型的文件时必须选择源语言和目标语言。

#### SEE ALSO
[Weblate Translation Memory Schema](https://docs.weblate.org/zh-cn/latest/contributing/schemas.md#schema-memory)

![image](screenshots/memory.webp)

你可以搜索翻译记忆库同时从 [自动建议](https://docs.weblate.org/zh-cn/latest/user/translating.md#machine-translation) 标签页编辑字符串。

### 管理界面

管理型用户拥有额外的翻译记忆库管理控制。在 管理 > 翻译记忆库 中，此页面列出 Weblate 实例的已上传共享条目、共享条目和总条目。根据权限不同，它可导入上传的共享记忆库，删除上传的条目，下载已上传的、共享的、或者所有条目为 JSON 或 TMX 文件。

#### Versionadded
Added in version 4.12.

项目翻译记忆库视图也允许重建部分或完整的项目翻译记忆库。所选部件或项目的自动生成条目被删除，记忆库在后台从当前翻译再次被填充。从文件导入的条目将被保留。

### 管理界面

有几个管理命令可以控制翻译记忆库的内容。这些命令将翻译记忆库视同一个整体进行操作，不受作用域影响（除非通过参数进行请求）：

[`dump_memory`](https://docs.weblate.org/zh-cn/latest/admin/management.md#weblate-admin-dump_memory)
: 将记忆库导入 JSON

[`import_memory`](https://docs.weblate.org/zh-cn/latest/admin/management.md#weblate-admin-import_memory)
: 将 TMX 或 JSON 文件导入翻译记忆库

[`cleanup_memory`](https://docs.weblate.org/zh-cn/latest/admin/management.md#weblate-admin-cleanup_memory)
: 从翻译记忆库中删除所有未提交状态的条目

#### Versionadded
Added in version 4.14.

Weblate API 涵盖了翻译记忆库。这允许出于不同目的或基于翻译周期事件的自动操控。
