Coverage for app/venv/lib/python3.14/site-packages/weblate/machinery/dummy.py: 0%
31 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4from __future__ import annotations
6from typing import TYPE_CHECKING
8from .base import (
9 GlossaryMachineTranslationMixin,
10 MachineTranslation,
11)
13if TYPE_CHECKING:
14 from .base import (
15 DownloadTranslations,
16 )
19class DummyTranslation(MachineTranslation):
20 """Dummy machine translation for testing purposes."""
22 name = "Dummy"
23 settings_form = None
25 def download_languages(self):
26 """
27 List supported languages.
29 Dummy translation supports just Czech language.
30 """
31 return ("en", "cs", "de")
33 def download_translations(
34 self,
35 source_language,
36 target_language,
37 text: str,
38 unit,
39 user,
40 threshold: int = 75,
41 ) -> DownloadTranslations:
42 """
43 Download translations.
45 Dummy translation supports just few phrases.
46 """
47 if source_language == "en" and text.strip() == "Hello, world!":
48 yield {
49 "text": "Nazdar světe!",
50 "quality": self.max_score,
51 "service": "Dummy",
52 "source": text,
53 }
54 yield {
55 "text": "Ahoj světe!",
56 "quality": self.max_score,
57 "service": "Dummy",
58 "source": text,
59 }
60 if source_language == "de" and text.strip() == "Hallo, Welt!":
61 yield {
62 "text": "Ahoj německý světe!",
63 "quality": self.max_score,
64 "service": "Dummy",
65 "source": text,
66 }
67 if source_language == "en" and text.strip() == "Hello, [X7X]!":
68 yield {
69 "text": "Nazdar [X7X ]!",
70 "quality": self.max_score,
71 "service": "Dummy",
72 "source": text,
73 }
76class DummyGlossaryTranslation(DummyTranslation, GlossaryMachineTranslationMixin):
77 """Dummy glossary translation for testing purposes."""
79 glossary_count_limit = 1
81 def download_translations(
82 self,
83 source_language,
84 target_language,
85 text: str,
86 unit,
87 user,
88 threshold: int = 75,
89 ) -> DownloadTranslations:
90 """Translate with glossary."""
91 self.get_glossary_id(source_language, target_language, unit)
92 return super().download_translations(
93 source_language, target_language, text, unit, user, threshold
94 )
96 def list_glossaries(self) -> dict[str, str]:
97 """List glossaries."""
98 return {}
100 def delete_glossary(self, glossary_id: str) -> None:
101 """Delete glossary."""
102 return
104 def delete_oldest_glossary(self) -> None:
105 """Delete oldest glossary."""
106 return self.delete_glossary("")
108 def create_glossary(
109 self, source_language: str, target_language: str, name: str, tsv: str
110 ) -> None:
111 """Create glossary."""
112 return