Machine translation

Weblate has builtin support for several machine translation services and it’s up to administrator to enable them. The services have different terms of use, so please check whether you are allowed to use them before enabling in Weblate. The individual services are enabled using MACHINE_TRANSLATION_SERVICES.

The source language can be configured at Project configuration.

Amagama

Special installation of tmserver run by Virtaal authors.

To enable this service, add weblate.trans.machine.tmserver.AmagamaTranslation to MACHINE_TRANSLATION_SERVICES.

Apertium

A free/open-source machine translation platform providing translation to limited set of languages.

The recommended way how to use Apertium is to run own Apertium APy server.

Alternatively you can use https://www.apertium.org/apy if you don’t expect to make too many requests.

To enable this service, add weblate.trans.machine.apertium.ApertiumAPYTranslation to MACHINE_TRANSLATION_SERVICES.

Glosbe

Free dictionary and translation memory for almost every living language.

API is free to use, regarding indicated data source license. There is a limit of call that may be done from one IP in fixed period of time, to prevent from abuse.

To enable this service, add weblate.trans.machine.glosbe.GlosbeTranslation to MACHINE_TRANSLATION_SERVICES.

See also

Glosbe website

Google Translate

Machine translation service provided by Google.

This service uses Translation API and you need to obtain API key and enable billing on Google API console.

To enable this service, add weblate.trans.machine.google.GoogleTranslation to MACHINE_TRANSLATION_SERVICES.

Microsoft Translator

Deprecated since version 2.10.

Note

This service is deprecated by Microsoft as needs to be replaced by Microsoft Cognitive Services Translator.

Machine translation service provided by Microsoft, it’s known as Bing Translator as well.

You need to register at Azure market and use Client ID and secret from there.

To enable this service, add weblate.trans.machine.microsoft.MicrosoftTranslation to MACHINE_TRANSLATION_SERVICES.

Microsoft Cognitive Services Translator

New in version 2.10.

Note

This is replacement service for Microsoft Translator.

Machine transation service provided by Microsoft in Azure portal as a one of Cognitive Services.

You need to register at Azure portal and use key you obtain there.

To enable this service, add weblate.trans.machine.microsoft.MicrosoftCognitiveTranslation to MACHINE_TRANSLATION_SERVICES.

MyMemory

Huge translation memory with machine translation.

Free, anonymous usage is currently limited to 100 requests/day, or to 1000 requests/day when you provide contact email in MT_MYMEMORY_EMAIL. you can also ask them for more.

To enable this service, add weblate.trans.machine.mymemory.MyMemoryTranslation to MACHINE_TRANSLATION_SERVICES.

tmserver

You can run your own translation memory server which is bundled with Translate-toolkit and let Weblate talk to it. You can also use it with amaGama server, which is enhanced version of tmserver.

First you will want to import some data to the translation memory:

To enable this service, add weblate.trans.machine.tmserver.TMServerTranslation to MACHINE_TRANSLATION_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

Now you can start tmserver to listen to your requests:

tmserver -d /var/lib/tm/db

And configure Weblate to talk to it:

MT_TMSERVER = 'http://localhost:8888/tmserver/'

Yandex Translate

Machine translation service provided by Yandex.

This service uses Translation API and you need to obtain API key from Yandex.

To enable this service, add weblate.trans.machine.yandex.YandexTranslation to MACHINE_TRANSLATION_SERVICES.

Weblate

Weblate can be source of machine translation as well. There are two services to provide you results - one does exact search for string, the other one finds all similar strings.

First one is useful for full string translations, the second one for finding individual phrases or words to keep the translation consistent.

To enable these services, add weblate.trans.machine.weblatetm.WeblateSimilarTranslation (for similar string matching) and/or weblate.trans.machine.weblatetm.WeblateTranslation (for exact string matching) to MACHINE_TRANSLATION_SERVICES.

Note

For similarity matching, it is recommended to have Whoosh 2.5.2 or later, earlier versions can cause infinite looks under some occasions.

Custom machine translation

You can also implement own machine translation services using few lines of Python code. Following example implements translation to fixed list of languages using dictionary Python module:

# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2017 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 <http://www.gnu.org/licenses/>.
#
'''
Machine translation example.
'''

from weblate.trans.machine.base import MachineTranslation
import dictionary


class SampleTranslation(MachineTranslation):
    '''
    Sample machine translation interface.
    '''
    name = 'Sample'

    def download_languages(self):
        '''
        Returns list of languages your machine translation supports.
        '''
        return set(('cs',))

    def download_translations(self, source, language, text, unit, user):
        '''
        Returns tuple with translations.
        '''
        return [(t, 100, self.name, text) for t in dictionary.translate(text)]

You can list own class in MACHINE_TRANSLATION_SERVICES and Weblate will start using that.