~cytrogen/evi-run

ref: bec77f28c7e477435ca5db8dd5437c63f48aaaa9 evi-run/I18N/factory.py -rw-r--r-- 720 bytes
bec77f28 — Bendy Simplify configuration examples in README 6 months ago
                                                                                
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
from fluent_compiler.bundle import FluentBundle
from fluentogram import FluentTranslator, TranslatorHub

from config import AVAILABLE_LANGUAGES, DEFAULT_LANGUAGE, LANGUAGE_FALLBACKS

DIR_PATH = 'I18N'


def i18n_factory() -> TranslatorHub:
    translators = []
    for lang in AVAILABLE_LANGUAGES:
        translators.append(
            FluentTranslator(
                locale=lang,
                translator=FluentBundle.from_files(
                    locale=lang,
                    filenames=[f'{DIR_PATH}/{lang}/txt.ftl'],
                    use_isolating=False)
            )
        )
    
    return TranslatorHub(
        LANGUAGE_FALLBACKS,
        translators,
        root_locale=DEFAULT_LANGUAGE,
    )