base_loom_server.translations

source module base_loom_server.translations

Functions

source get_language_names()list[str]

Get a list of all language files found in LOCALE_FILES.

Add "English" and omit "default.json".

source get_default_dict()dict[str, str]

Get the default translation dict.

The data in the file is mostly a dict of word or phrase: context where context is a hint to people doing the translation. For those items the returned data is word or phrase: word or phrase (the context is ignored).

For keys in the METADATA_KEYS, the data is copied directly.

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

Get the translation dict for the specified language.

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.

Raises

  • FileNotFoundError If a file is not found.

  • RecursionError If a circular "_extends" reference is found.

  • RuntimeError

source read_one_translation_file(translation_file: Traversable, valid_keys: set[str] | KeysView, 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 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.