机器翻译
内建了几种及其翻译服务的支持,并且每一个可以由管理员使用 MT_SERVICES
来打开。它们受到自己的使用条款约束,因此请确认允许您以所需要的方式来使用它。
源语言可以在 项目配置 中进行配置。
amaGama
由 Virtaal 作者运行的 tmserver 的特殊安装。
通过将 weblate.machinery.tmserver.AmagamaTranslation
添加到 MT_SERVICES
来打开这个服务。
Apertium
一个自由软件机器翻译平台,提供有限语言的翻译。
使用 Apertium的推荐方式是运行您自己的 Apertium-APy 服务器 。
通过将 weblate.machinery.apertium.ApertiumAPYTranslation
添加到 MT_SERVICES
中,并设置 MT_APERTIUM_APY
来开启这项服务。
AWS
3.1 新版功能.
Amazon Translate 是神经机器翻译服务,用于将英语与广泛支持的语言进行互译。
通过将
weblate.machinery.aws.AWSTranslation
添加到MT_SERVICES
来打开这项服务。安装 boto3 模块。
配置 Weblate 。
Baidu API 机器翻译
3.2 新版功能.
由百度提供的机器翻译服务。
这项服务使用 API ,并且您需要从百度获得 ID 和 API 密钥来使用它。
通过将 weblate.machinery.baidu.BaiduTranslation
添加到 MT_SERVICES
并设置 MT_BAIDU_ID
和 MT_BAIDU_SECRET
来打开这项服务。
DeepL
2.20 新版功能.
DeepL 是付费服务,提供一些语言的良好机器翻译。您需要购买 DeepL API 订阅,或者您可以使用传统的 DeepL Pro (classic) 计划。
通过将 weblate.machinery.deepl.DeepLTranslation
添加到 MT_SERVICES
,并设置 MT_DEEPL_KEY
来打开这项服务。
提示
如果你有一个计算机辅助翻译工具(CAT )订阅,你应该使用”v1 API”,而不是 Weblate 默认使用的”v2”(在这种情况下,这不是真正的 API 版本)。如果你使用的是免费计划而不是付费计划,你必须使用 https://api-free.deepl.com/
而不是 https://api.deepl.com/
你可以通过 MT_DEEPL_API_URL
来调整它们的参数。
LibreTranslate
4.7.1 新版功能.
LibreTranslate 是一项自由开源的机器翻译服务。公共实例需要 API 密钥,但 LibreTranslate 可以自托管,并且有几个镜像可以免费使用 API。
通过将 weblate.machinery.libretranslate.LibreTranslateTranslation
添加到 MT_SERVICES
并设置 MT_LIBRETRANSLATE_API_URL
来打开这项服务。如果实例需要 API 密钥,你也必须设置 MT_LIBRETRANSLATE_KEY
。
Glosbe
几乎所有现存语言的免费词典和翻译记忆库。
The API is gratis to use, but usage of the translations is subject to the license of the used data source. There is a limit of calls that may be done from one IP in a set period of time, to prevent abuse.
通过将 weblate.machinery.glosbe.GlosbeTranslation
添加到 MT_SERVICES
来打开这项服务。
参见
Google 翻译
Google 提供的机器翻译服务。
这项服务使用了 Google Translation API ,您需要得到 API 密钥,并在 Google API 控制台打开记费。
将 weblate.machinery.google.GoogleTranslation
添加到 MT_SERVICES
,并设置 MT_GOOGLE_KEY
来打开这项服务。
Google Translate API V3(高级版)
Google 云服务提供的机器翻译服务。
这项服务在如何进行身份验证方面不同于前面的服务。将 weblate.machinery.googlev3.GoogleV3Translation
添加到 MT_SERVICES
,并通过后面的设置来允许服务
如果 location 失败,您还需要指定 MT_GOOGLE_LOCATION
。
微软认知服务翻译工具
2.10 新版功能.
由微软在 Azure 门户提供的机器翻译服务,是认知服务的一种。
Weblate 使用了 Translator API V3。
为了允许这项服务,将 weblate.machinery.microsoft.MicrosoftCognitiveTranslation
添加到 MT_SERVICES
,并设置 MT_MICROSOFT_COGNITIVE_KEY
。
Translator Text API V2
您在 Translator API V2 使用的密钥可以在 API 3 中使用。
Translator Text API V3
您需要在 Azure 门户注册,并使用得到的密钥。关于新的 Azure 密钥,您还需要设置 MT_MICROSOFT_REGION
为您的服务设置地区。
微软术语服务
2.19 新版功能.
微软术语服务 API 允许您通过网络服务以编程方式访问语言门户中可用的术语、定义和用户界面(UI)字符串。
通过将 weblate.machinery.microsoftterminology.MicrosoftTerminologyService
添加到 MT_SERVICES
来打开这项服务。
参见
ModernMT
4.2 新版功能.
通过将 weblate.machinery.modernmt.ModernMTTranslation
添加到 MT_SERVICES
,并配置 MT_MODERNMT_KEY
来打开这项服务。
MyMemory
使用机器翻译的巨量翻译记忆库。
自由匿名使用,当前限制为 100 个请求/天,或者在 MT_MYMEMORY_EMAIL
中提供电子邮箱联系地址时限制为 1000 个请求/天。您还可以向他们请求更多。
通过将 weblate.machinery.mymemory.MyMemoryTranslation
添加到 MT_SERVICES
,并设置 MT_MYMEMORY_EMAIL
来打开这项服务。
网易见外 API 机器翻译
3.3 新版功能.
网易提供的机器翻译服务。
这项服务使用 API ,您需要从网易获取密钥和密码。
通过将 weblate.machinery.youdao.NeteaseSightTranslation
添加到 MT_SERVICES
并设置 MT_NETEASE_KEY
和 MT_NETEASE_SECRET
来打开这项服务。
tmserver
您可以通过使用 Translate-toolkit 绑定的一个服务器并与之对话,来运行您自己的翻译服务器。您还可以将它与 amaGama 服务器一起使用,它是 tmserver 的增强版本。
首先您会想要将一些数据导入翻译记忆库:
2. Turn on this service by adding weblate.machinery.tmserver.TMServerTranslation
to
MT_SERVICES
.
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
启动 tmserver 来收听您的请求:
tmserver -d /var/lib/tm/db
配置 Weblate 来与之对话:
MT_TMSERVER = "http://localhost:8888/tmserver/"
Yandex 翻译
Yandex 提供的机器翻译服务。
这项服务使用翻译 API ,您需要从 Yandex 得到 API 密钥。
通过将 weblate.machinery.yandex.YandexTranslation
添加到 MT_SERVICES
,并设置 MT_YANDEX_KEY
来打开这项服务。
有道智云 API 机器翻译
3.2 新版功能.
有道提供的机器翻译服务。
这项服务使用 API ,您需要从有道获得 ID 和 API 密钥。
通过将 weblate.machinery.youdao.YoudaoTranslation
添加到 MT_SERVICES
,并设置 MT_YOUDAO_ID
和 MT_YOUDAO_SECRET
来打开这项服务。
Weblate
Weblate 也可以是机器翻译的来源。它基于 Woosh 全文引擎,并提供精确和不精确的匹配。
通过将 weblate.machinery.weblatetm.WeblateTranslation
添加到 MT_SERVICES
来打开这项服务。
Weblate 翻译记忆库
2.20 新版功能.
翻译记忆库 也可以用作机器翻译建议的来源。
通过将 weblate.memory.machine.WeblateMemory
添加到 MT_SERVICES
,来打开这项服务。这项服务默认打开。
SAP 翻译中心
SAP 提供的机器翻一下服务。
你需要有 SAP 账户(且 SAP Cloud Platform 中 SAP Translation Hub 已启用 )来使用这项服务。
通过将 weblate.machinery.saptranslationhub.SAPTranslationHub
添加到 MT_SERVICES
,并设置对沙箱或生产 API 的适当访问,来打开这项服务。
备注
为了访问 Sandbox API ,您需要设置 MT_SAP_BASE_URL
和 MT_SAP_SANDBOX_APIKEY
。
为了访问生产 API ,您需要设置 MT_SAP_BASE_URL
、 MT_SAP_USERNAME
和 MT_SAP_PASSWORD
。
定制化的机器翻译
您还可以用几行 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}
你可以在 MT_SERVICES
中列出自己的类,Weblate 就会开始使用它了。