base_loom_server.translations

source module base_loom_server.translations

Functions

source get_language_names()list[str]

Get a sorted list of all language files found in LOCALE_FILES.

Omit "default.json".

source get_default_dict()dict[str, str]

Get the default translation dict.

source get_translation_dict(language: str, *, logger: logging.Logger | None = None, html_escape: bool = True, dir_: Traversable = LOCALE_FILES)dict[str, str]

Get the translation dict for the specified language.

All missing phrases use the phrase from "default.json".

Parameters

  • language : str Name of one of the available language files, or "English" for English. Must not be "" or "default".

  • logger : logging.Logger | None Logger, which is created if None.

  • dir_ : Traversable Directory containing the non-default translation files. Use the default value except in unit tests.

  • html_escape : bool Run the values through html.escape?

Raises

  • FileNotFoundError If a file is not found.

  • RuntimeError

source read_one_translation_file(translation_file: Traversable, valid_keys: set[str] | KeysView[str], logger: logging.Logger)dict[str, str]

Read and parse one language translation file.

Parameters

  • translation_file : Traversable Path to translation file.

  • valid_keys : set[str] | KeysView[str] Keys that are allowed in the translation dict. Invalid keys are purged with a logged warning.

  • logger : logging.Logger Logger.

Returns

  • The translation dict a dict of English word or phrase: translation.

Raises

  • FileNotFoundError If the file is not found.