File size: 1,581 Bytes
3bfe3dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from enum import Enum, unique

from pydantic import BaseModel, computed_field


@unique
class Languages(Enum):
    az = "az"
    bn = "bn"
    de = "de"
    em = "em"
    es = "es"
    fa = "fa"
    fr = "fr"
    he = "he"
    hu = "hu"
    id = "id"
    it = "it"
    ja = "ja"
    ko = "ko"
    pl = "pl"
    pt = "pt"
    ru = "ru"
    tr = "tr"
    uk = "uk"
    ur = "ur"
    vi = "vi"
    yo = "yo"
    zh = "zh"
    zh_hant = "zh-hant"


class TranslationDoc(BaseModel):
    official_lang: str = "en"
    translation_lang: str
    original_file: str
    translation_file: str | None = None
    translation_exists: bool


class Summary(BaseModel):
    lang: str
    files_analyzed: int = 0
    files_translated: int = 0
    files_outdated: int = 0
    files_missing_translation: int = 0
    files: list[TranslationDoc] = []

    @computed_field  # type: ignore
    @property
    def percentage_missing_translation(self) -> float:
        try:
            return (
                100 * float(self.files_missing_translation) / float(self.files_analyzed)
            )
        except Exception:
            return 0.0

    def append_file(self, doc: TranslationDoc) -> None:
        self.files.append(doc)
        self.files_analyzed += 1

        if doc.translation_exists:
            self.files_translated += 1

        if not doc.translation_exists:
            self.files_missing_translation += 1

    def first_missing_translation_files(self, length: int = 10) -> list[TranslationDoc]:
        return list(filter(lambda d: not d.translation_exists, self.files))[:length]