Coverage for app/venv/lib/python3.14/site-packages/weblate/machinery/types.py: 95%

54 statements  

« 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 

4 

5from __future__ import annotations 

6 

7from collections.abc import Iterable 

8from typing import TYPE_CHECKING, NotRequired, TypeAlias, TypedDict 

9 

10from django.db.models import TextChoices 

11from django.utils.translation import pgettext_lazy 

12 

13if TYPE_CHECKING: 13 ↛ 14line 13 didn't jump to line 14 because the condition on line 13 was never true

14 from weblate.trans.models import Project 

15 

16 from .base import BatchMachineTranslation 

17 

18 

19class SourceLanguageChoices(TextChoices): 

20 AUTO = "auto", pgettext_lazy("Source language selection", "Automatic selection") 

21 SOURCE = ( 

22 "source", 

23 pgettext_lazy("Source language selection", "Component source language"), 

24 ) 

25 SECONDARY = ( 

26 "secondary", 

27 pgettext_lazy( 

28 "Source language selection", 

29 "Secondary language defined in project or component", 

30 ), 

31 ) 

32 

33 

34class SettingsDict(TypedDict, total=False): 

35 key: str 

36 url: str 

37 secret: str 

38 email: str 

39 username: str 

40 password: str 

41 enable_mt: bool 

42 domain: str 

43 base_url: str 

44 endpoint_url: str 

45 region: str 

46 credentials: str 

47 project: str 

48 location: str 

49 formality: str 

50 model: str 

51 persona: str 

52 style: str 

53 custom_model: str 

54 bucket_name: str 

55 context_vector: str 

56 deployment: str 

57 azure_endpoint: str 

58 source_language: SourceLanguageChoices 

59 _project: Project 

60 

61 

62class TranslationResultDict(TypedDict): 

63 text: str 

64 quality: int 

65 service: str 

66 source: str 

67 original_source: NotRequired[str] 

68 show_quality: NotRequired[bool] 

69 origin: NotRequired[str | None] 

70 origin_url: NotRequired[str | None] 

71 delete_url: NotRequired[str | None] 

72 

73 

74class UnitMemoryResultDict(TypedDict, total=False): 

75 quality: list[int] 

76 translation: list[str] 

77 origin: list[BatchMachineTranslation | None] 

78 

79 

80DownloadTranslations: TypeAlias = Iterable[TranslationResultDict] 

81DownloadMultipleTranslations: TypeAlias = dict[str, list[TranslationResultDict]]