translator module¶
Note
This module is imports as from .. import *
. This means that there
is no need to import it separately or use ezbotf.translator.Translator
.
You can simply use ezbotf.Translator
as example.
Here is defined only Translator
class that helps with the translations management.
Translator¶
- class ezbotf.translator.Translator(lang_dir: Path, logger_group: LoggerGroup | str, default_lang: str = 'en', desired_lang: str = 'en')¶
Translator object provides the easy methods to translate text
- Variables:
lang_dir – Path to the directory with the translation files
logger_group – Group for the translator logger
default_lang – Default language (Lang code)
desired_lang – Desired language to use (Lang code)
translations – TOML dictionary with the loaded translations
logger – Logger of the translator
- __init__(lang_dir: Path, logger_group: LoggerGroup | str, default_lang: str = 'en', desired_lang: str = 'en')¶
- Parameters:
lang_dir – Path to the directory with the translation files
logger_group – Group for the translator logger
default_lang – Default language (Lang code)
desired_lang – Desired language to use (Lang code)
- load_file(path: Path) bool ¶
Loads a file to the translations dictionary. Note, that if language is not exists, DEBUG log will be recorded about it
- Parameters:
path – Path to the file
- Returns:
True if language is successfully loaded, otherwise False
- load_language(language: str) bool ¶
Loads specific language to translations dictionary
- Parameters:
language – Language to load
- Returns:
True if language is loaded, otherwise False
- initialize()¶
Initializes the default translation file (loads it as default_lang)