Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion weblate/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
from weblate.auth.utils import validate_team_assignable_user
from weblate.formats.models import EXPORTERS
from weblate.lang.models import Language
from weblate.machinery.base import MACHINERY_DEFAULT_THRESHOLD
from weblate.machinery.models import validate_service_configuration
from weblate.memory.models import MEMORY_LOOKUP_LIMIT, Memory
from weblate.screenshots.models import Screenshot
Expand Down Expand Up @@ -2424,7 +2425,7 @@ def get_fuzzy_match(
source_language: Language,
target_language: Language,
text: str,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
):
base = queryset.filter(
source_language=source_language,
Expand Down
4 changes: 2 additions & 2 deletions weblate/examples/mt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from typing import TYPE_CHECKING

from weblate.machinery.base import MachineTranslation
from weblate.machinery.base import MACHINERY_DEFAULT_THRESHOLD, MachineTranslation

if TYPE_CHECKING:
from weblate.auth.models import User
Expand All @@ -34,7 +34,7 @@ def download_translations(
text: str,
unit: Unit | None,
user: User | None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Return tuple with translations."""
response = self.request(
Expand Down
8 changes: 6 additions & 2 deletions weblate/machinery/alibaba.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

from requests.exceptions import JSONDecodeError

from .base import MachineTranslation, MachineTranslationError
from .base import (
MACHINERY_DEFAULT_THRESHOLD,
MachineTranslation,
MachineTranslationError,
)
from .forms import AlibabaMachineryForm

if TYPE_CHECKING:
Expand Down Expand Up @@ -339,7 +343,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from a service."""
body_params = {
Expand Down
3 changes: 2 additions & 1 deletion weblate/machinery/apertium.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.translation import gettext

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
ResponseStatusMachineTranslation,
)
from .forms import URLMachineryForm
Expand Down Expand Up @@ -141,7 +142,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from Apertium."""
args = {
Expand Down
3 changes: 2 additions & 1 deletion weblate/machinery/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.functional import cached_property

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
GlossaryDoesNotExistError,
GlossaryMachineTranslationMixin,
)
Expand Down Expand Up @@ -70,7 +71,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
params = {
"Text": text,
Expand Down
3 changes: 2 additions & 1 deletion weblate/machinery/baidu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING, ClassVar

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
MachineryRateLimitError,
MachineTranslation,
MachineTranslationError,
Expand Down Expand Up @@ -103,7 +104,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from a service."""
salt, sign = self.signed_salt(
Expand Down
22 changes: 12 additions & 10 deletions weblate/machinery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
SourceLanguageChoices,
)

MACHINERY_DEFAULT_THRESHOLD = 80

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator

Expand Down Expand Up @@ -148,7 +150,7 @@ def validate_settings(self) -> None:
self.validate_target_language,
[("test", None)],
None,
75,
MACHINERY_DEFAULT_THRESHOLD,
)
except Exception as error:
raise ValidationError(
Expand Down Expand Up @@ -701,7 +703,7 @@ def translate(
self,
unit: Unit,
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
*,
source_language: Language | None = None,
):
Expand Down Expand Up @@ -751,7 +753,7 @@ def download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
"""
Download dictionary of a lists of possible translations from a service.
Expand All @@ -771,7 +773,7 @@ def _translate(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
return {
text: result
Expand All @@ -790,7 +792,7 @@ def _translate_sources(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> list[list[TranslationResultDict]]:
output: list[list[TranslationResultDict]] = [[] for _source in sources]
pending: dict[str, list[tuple[int, Unit | None, str, dict[str, str]]]] = (
Expand Down Expand Up @@ -880,7 +882,7 @@ def _download_pending_translations(
source_language,
target_language,
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> None:
remaining_keys = list(pending)
while remaining_keys:
Expand Down Expand Up @@ -945,7 +947,7 @@ def download_pending_translations(
target_language,
sources: list[tuple[str, Unit | None, int]],
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
return self.download_multiple_translations(
source_language,
Expand Down Expand Up @@ -976,7 +978,7 @@ def batch_translate(
self,
units: list[Unit] | UnitQuerySet,
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
*,
source_language: Language | None = None,
) -> None:
Expand Down Expand Up @@ -1058,7 +1060,7 @@ def download_translations(
text: str,
unit: Unit | None,
user: User | None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""
Download list of possible translations from a service.
Expand All @@ -1078,7 +1080,7 @@ def download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
return {
text: list(
Expand Down
4 changes: 2 additions & 2 deletions weblate/machinery/cyrtranslit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from weblate.lang.models import Language

from .base import MachineTranslation
from .base import MACHINERY_DEFAULT_THRESHOLD, MachineTranslation
from .types import TranslationResultDict

if TYPE_CHECKING:
Expand Down Expand Up @@ -97,7 +97,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
):
"""Download list of possible translations from a service."""
import cyrtranslit # noqa: PLC0415
Expand Down
3 changes: 2 additions & 1 deletion weblate/machinery/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from requests.exceptions import HTTPError, RequestException

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
BatchMachineTranslation,
GlossaryDoesNotExistError,
GlossaryMachineTranslationMixin,
Expand Down Expand Up @@ -149,7 +150,7 @@ def download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user: User | None = None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
"""Download list of possible translations from a service."""
texts = [text for text, _unit in sources]
Expand Down
5 changes: 3 additions & 2 deletions weblate/machinery/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
GlossaryMachineTranslationMixin,
MachineTranslation,
)
Expand Down Expand Up @@ -37,7 +38,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""
Download translations.
Expand Down Expand Up @@ -92,7 +93,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Translate with glossary."""
self.get_glossary_id(source_language, target_language, unit)
Expand Down
4 changes: 2 additions & 2 deletions weblate/machinery/glosbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import TYPE_CHECKING

from .base import MachineTranslation
from .base import MACHINERY_DEFAULT_THRESHOLD, MachineTranslation

if TYPE_CHECKING:
from .base import DownloadTranslations
Expand Down Expand Up @@ -33,7 +33,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from a service."""
params = {
Expand Down
8 changes: 6 additions & 2 deletions weblate/machinery/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

from requests.exceptions import RequestException

from .base import MachineTranslation, MachineTranslationError
from .base import (
MACHINERY_DEFAULT_THRESHOLD,
MachineTranslation,
MachineTranslationError,
)
from .forms import KeyMachineryForm

if TYPE_CHECKING:
Expand Down Expand Up @@ -73,7 +77,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from a service."""
response = self.request(
Expand Down
3 changes: 2 additions & 1 deletion weblate/machinery/googlev3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from google.oauth2 import service_account

from .base import (
MACHINERY_DEFAULT_THRESHOLD,
GlossaryAlreadyExistsError,
GlossaryDoesNotExistError,
GlossaryMachineTranslationMixin,
Expand Down Expand Up @@ -102,7 +103,7 @@ def download_translations(
text: str,
unit,
user,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadTranslations:
"""Download list of possible translations from a service."""
request = {
Expand Down
8 changes: 6 additions & 2 deletions weblate/machinery/libretranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from typing import TYPE_CHECKING, ClassVar

from .base import BatchMachineTranslation, MachineTranslationError
from .base import (
MACHINERY_DEFAULT_THRESHOLD,
BatchMachineTranslation,
MachineTranslationError,
)
from .forms import LibreTranslateMachineryForm

if TYPE_CHECKING:
Expand Down Expand Up @@ -106,7 +110,7 @@ def download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
"""Download list of possible translations from a service."""
texts = [text for text, _unit in sources]
Expand Down
11 changes: 6 additions & 5 deletions weblate/machinery/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
get_glossary_tuples,
)
from weblate.machinery.base import (
MACHINERY_DEFAULT_THRESHOLD,
BatchMachineTranslation,
MachineTranslationError,
)
Expand Down Expand Up @@ -239,7 +240,7 @@ def _translate_sources(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> list[list[TranslationResultDict]]:
started_cache = self._ensure_secondary_context_cache()
try:
Expand Down Expand Up @@ -1051,7 +1052,7 @@ def download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
return self._download_multiple_translations(
source_language, target_language, sources, user, threshold
Expand All @@ -1063,7 +1064,7 @@ def download_pending_translations(
target_language,
sources: list[tuple[str, Unit | None, int]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
) -> DownloadMultipleTranslations:
return self._download_multiple_translations(
source_language,
Expand All @@ -1082,7 +1083,7 @@ def _download_multiple_translations(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
*,
source_occurrences: list[int] | None = None,
) -> DownloadMultipleTranslations:
Expand All @@ -1105,7 +1106,7 @@ def _download_multiple_translations_with_context_cache(
target_language,
sources: list[tuple[str, Unit | None]],
user=None,
threshold: int = 75,
threshold: int = MACHINERY_DEFAULT_THRESHOLD,
*,
source_occurrences: list[int] | None = None,
) -> DownloadMultipleTranslations:
Expand Down
Loading
Loading