配置自动建议

在 4.13 版更改: 在Weblate 4.13之前,这些服务是在 :ref:`config`中配置的。

内置了对几种机器翻译和翻译记忆服务的支持。每个服务都可以由管理员在整个网站或项目设置中打开:

../_images/project-machinery.png

备注

它们受到其使用条款的约束,所以确保你被允许以你想要的方式使用它们。

该服务从 component`配置的源文件进行翻译,见 :ref:`component-source_language

参见

自动建议

Amagama

服务 ID

amagama

配置

此服务无配置。

由 Virtaal 作者运行的 tmserver 的特殊安装。

Apertium APy

服务 ID

apertium-apy

配置

url

API 网址

一个自由软件机器翻译平台,提供有限语言的翻译。

使用 Apertium的推荐方式是运行您自己的 Apertium-APy 服务器。

AWS

3.1 新版功能.

服务 ID

aws

配置

key

访问密钥 ID

secret

API 密钥

region

区域名

Amazon Translate 是神经机器翻译服务,用于将英语与广泛支持的语言进行互译。

百度

3.2 新版功能.

服务 ID

baidu

配置

key

客户 ID

secret

客户端 secret

由百度提供的机器翻译服务。

这项服务使用 API,并且您需要从百度获得 ID 和 API 密钥来使用它。

DeepL

2.20 新版功能.

服务 ID

deepl

配置

url

API 网址

key

API 密钥

DeepL 是付费服务,提供一些语言的良好机器翻译。您需要购买 DeepL API 订阅,或者您可以使用传统的 DeepL Pro (classic) 计划。

用于 DeepL 服务的 API URL。在撰写本文时,有v1版API以及v2版API的免费和付费版本。

https://api.deepl.com/v2/ (Weblate 默认)

用于付费计划的 API 用量,订阅是基于用量的。

https://api-free.deepl.com/v2/

用于免费计划的 API 用量,订阅是基于用量的。

https://api.deepl.com/v1/

用于计算机辅助翻译工具,可以按用户订阅。

之前 Weblate 被 DeepL 归类为计算机辅助翻译(CAT)工具,所以应该使用 v1 API,但现在应该使用 v2 API。因此它默认为 v2,如果您现在有一个计算机辅助翻译工具(CAT )订阅,并希望 Weblate 使用它,您可以将其更改为 v1。

最简单的方法就是在浏览器中打开如下网址:

https://api.deepl.com/v2/translate?text=Hello&target_lang=FR&auth_key=XXX

将链接中的xxx替换为你自己deepl账号的auth_key。如果你收到了一个包含有”Bonjour”(你好)的JSON对象,说明URL是正确,否则,试试其他方式。

Glosbe

服务 ID

glosbe

配置

此服务无配置。

几乎所有现存语言的免费词典和翻译记忆库。

其 API 可免费使用,但翻译的使用受到所用数据源许可证的约束。为防止滥用,在一段时间内,可以从一个 IP 进行的调用是有限制的。

参见

Glosbe 网站

Google 翻译

服务 ID

google-translate

配置

key

API 密钥

Google 提供的机器翻译服务。

这项服务使用了 Google Translation API,您需要得到 API 密钥,并在 Google API 控制台打开记费。

Google 翻译 API v3

服务 ID

google-translate-api-v3

配置

credentials

Google 翻译服务账户信息

project

Google 翻译项目

location

Google 翻译位置

Google 云服务提供的机器翻译服务。

LibreTranslate

4.7.1 新版功能.

服务 ID

libretranslate

配置

url

API 网址

key

API 密钥

LibreTranslate 是一项自由开源的机器翻译服务。公共实例需要 API 密钥,但 LibreTranslate 可以自托管,并且有几个镜像可以免费使用 API。

``https://libretranslate.com/``(官方公开实例)

需要一个API密钥才能在该网站之外使用。

微软术语服务

2.19 新版功能.

服务 ID

microsoft-terminology

配置

此服务无配置。

微软术语服务 API 允许您通过网络服务以编程方式访问语言门户中可用的术语、定义和用户界面(UI)字符串。

微软翻译

2.10 新版功能.

服务 ID

microsoft-translator

配置

key

API 密钥

endpoint_url

应用端点网址

base_url

应用的基网址

可用选项:

api.cognitive.microsofttranslator.com – 全球(非区域)

api-apc.cognitive.microsofttranslator.com – 亚太

api-eur.cognitive.microsofttranslator.com – 欧洲

api-nam.cognitive.microsofttranslator.com – 北美

api.translator.azure.cn – China

region

应用区域

由微软在 Azure 门户提供的机器翻译服务,是认知服务的一种。

Weblate 使用了 Translator API V3。

Translator Text API V2

您在 Translator API V2 使用的密钥可以在 API 3 中使用。

Translator Text API V3

您需要在 Azure 门户注册,并使用得到的密钥。您还需要将新的 Azure 密钥的 ``region` 设置为您服务的语言环境。

提示

中国区 Azure 请使用你在 Azure 门户的端点。

ModernMT

4.2 新版功能.

服务 ID

modernmt

配置

url

API 网址

key

API 密钥

参见

ModernMT API,

MyMemory

服务 ID

mymemory

配置

email

联系电子邮箱

username

用户名

key

API 密钥

使用机器翻译的巨量翻译记忆库。

自由匿名使用,当前限制为 100 个请求/天,或者在 email 中提供电子邮箱联系地址时限制为 1000 个请求/天。您还可以向他们请求更多。

网易见外

3.3 新版功能.

服务 ID

netease-sight

配置

key

客户 ID

secret

客户端 secret

网易提供的机器翻译服务。

这项服务使用 API,您需要从网易获取密钥和密码。

SAP 翻译中心

服务 ID

sap-translation-hub

配置

url

API 网址

key

API 密钥

username

SAP 用户名

password

SAP 密码

enable_mt

启用机器翻译

SAP 提供的机器翻一下服务。

你需要有 SAP 账户(且 SAP Cloud Platform 中 SAP Translation Hub 已启用 )来使用这项服务。

除了术语数据库,你还可以配置是否使用机器翻译服务。

备注

要访问 Sandbox API,您需要设置 urlkey.

要访问生产性API,你需要设置 url, usernamepassword.

tmserver

服务 ID

tmserver

配置

url

API 网址

您可以通过使用 Translate-toolkit 绑定的一个服务器并与之对话,来运行您自己的翻译服务器。您还可以将它与 amaGama 服务器一起使用,它是 tmserver 的增强版本。

  1. 首先您会想要将一些数据导入翻译记忆库:

build_tmdb -d /var/lib/tm/db -s en -t cs locale/cs/LC_MESSAGES/django.po
build_tmdb -d /var/lib/tm/db -s en -t de locale/de/LC_MESSAGES/django.po
build_tmdb -d /var/lib/tm/db -s en -t fr locale/fr/LC_MESSAGES/django.po
  1. 启动 tmserver 来收听您的请求:

tmserver -d /var/lib/tm/db
  1. 配置Weblate与服务通信,默认地址为 http://localhost:8888/tmserver/.

Weblate

服务 ID

weblate

配置

此服务无配置。

Weblate机器翻译服务可以为Weblate内部已经翻译过的字符串提供翻译。它寻找现有字符串中的精确匹配。

Weblate 翻译记忆库

2.20 新版功能.

服务 ID

weblate-translation-memory

配置

此服务无配置。

使用 :ref:`translation-memory`作为机器翻译服务。任何过去翻译过的字符串(或上传到翻译记忆库)都可以用这种方式翻译。

Yandex

服务 ID

yandex

配置

key

API 密钥

Yandex 提供的机器翻译服务。

这项服务使用翻译 API,您需要从 Yandex 得到 API 密钥。

有道智云

3.2 新版功能.

服务 ID

youdao-zhiyun

配置

key

客户 ID

secret

客户端 secret

有道提供的机器翻译服务。

这项服务使用 API,您需要从有道获得 ID 和 API 密钥。

定制化的机器翻译

您还可以用几行 Python 代码来实现自己的机器翻译服务。此示例使用 dictionary Python 模块实现了一组确定的语言的机器翻译:

#
# Copyright © 2012–2022 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Machine translation example."""

import dictionary

from weblate.machinery.base import MachineTranslation


class SampleTranslation(MachineTranslation):
    """Sample machine translation interface."""

    name = "Sample"

    def download_languages(self):
        """Return list of languages your machine translation supports."""
        return {"cs"}

    def download_translations(
        self,
        source,
        language,
        text: str,
        unit,
        user,
        search: bool,
        threshold: int = 75,
    ):
        """Return tuple with translations."""
        for t in dictionary.translate(text):
            yield {"text": t, "quality": 100, "service": self.name, "source": text}

你可以在 WEBLATE_MACHINERY 中列出自己的类,Weblate 就会开始使用它了。