weblate/docs/admin/machine.rst
Michal Čihař 1edad24538
feat(machinery): improve LLMs translation prompting (#19944)
- pass additional info on glossaries
- use real examples from the project rather than hard-coded ones
- fallback to Weblate shipped examples that will be localized
- it is now possible to provide language-specific prompt customization

Fixes #19927
2026-06-10 17:58:15 +00:00

111 lines
4.4 KiB
ReStructuredText
Vendored

.. _machine-translation-setup:
Automatic suggestions
=====================
.. versionchanged:: 4.13
Prior to Weblate 4.13, the services were configured in the :ref:`config`.
The support for several machine translation and translation memory services is
built-in. Each service can be turned on by the administrator for whole site
(under :guilabel:`Automatic suggestions` in :ref:`management-interface`) or at
the project settings:
.. image:: /screenshots/project-machinery.webp
.. note::
They come subject to their terms of use, so ensure you are allowed to use
them how you want. Third-party services can receive source strings,
translations, and related context from Weblate.
The services translate from the source language as configured at
:ref:`component`, see :ref:`component-source_language`.
Per-project automatic suggestion can also be configured via the :ref:`api`.
.. seealso::
:ref:`machine-translation`
.. _mt-translation-services-priority:
Priority of machine translation and translation memory services
----------------------------------------------------------------
:ref:`mt-weblate-translation-memory` matches with 100% score take priority over machine translation services. If 100% match in translation memory is found, no machine translation is performed. If several 100% matches occur, the first one returned by the database is used.
Each machine translation service has a predefined maximum score it can produce. The use of installed translation services is ordered according to their maximum score. For each string with translation score lower than the service's maximum, the service is asked to produce a translation. Translations with a score exceeding the current one are accepted.
.. _mt-sources:
Source strings for the machine translation
------------------------------------------
.. versionadded:: 5.11
The origin of source strings for all third-party services can be configured.
This can be used to tweak the service to get the best results. Following choices are available:
:guilabel:`Automatic selection`
Chooses the best source language automatically.
This is the default behavior.
:guilabel:`Component source language`
Uses the component source language.
This was the behavior before the 5.11 release.
:guilabel:`Secondary language defined in project or component`
Use project :ref:`project-secondary_language` or component :ref:`component-secondary_language`.
Falls back to the automatic selection of the source language if the secondary language not configured.
.. _llm-translation-context:
LLM translation context
-----------------------
LLM-based automatic suggestion services receive additional context about each
translated string, when available. This includes the string context or
monolingual key, additional explanation, configured secondary-language
translation, plural information, failing quality checks, and placeholder
contents. Matching glossary entries are passed with their explanations and
selected flags, so duplicate glossary terms can be disambiguated.
You can add target-language-specific instructions in
:guilabel:`Language-specific instructions` using a JSON object mapping language
codes to text. Language codes have to exist in Weblate and are matched exactly;
whitespace is not ignored. Each instruction can contain up to 1000 characters.
Weblate first looks for the exact target language code and then falls back to
the base language code.
The added metadata is used only to guide the generated suggestion; the returned
translation still has to preserve the source placeholders and markup. Weblate
also sends a short previous chat exchange to LLM services to demonstrate the
expected JSON response format. The exchange uses bundled translated examples
when available for the source and target language pair, or language-neutral
formatting examples otherwise. Existing translations for the same target
language can be appended as additional examples.
.. include:: /snippets/machines-autogenerated.rst
.. _custom-machinery:
Custom machine translation
--------------------------
You can also implement your own machine translation services using a few lines
of Python code. Place the code in a module Weblate can import (see
:ref:`custom-module` or :ref:`docker-python-override`) and add fully qualified
class name to :setting:`WEBLATE_MACHINERY`.
.. literalinclude:: ../../weblate/examples/mt_service.py
:language: python
.. seealso::
* :ref:`custom-modules`
* :ref:`custom-module`
* :ref:`docker-python-override`