iccas.i18n package

Submodules

iccas.i18n.lib module

A simple and crappy i18n library written “for fun” and because neither gettext and python-i18n were optimal for my use case which requires reloading of translations when a change is made without restarting the interpreter/kernel and possibly without reloading the module.

class iccas.i18n.lib.NullTranslation[source]

Bases: iccas.i18n.lib.Translation

get(str_id, count, few_max=5, varname='count')[source]
Return type

str

class iccas.i18n.lib.Translation(lang, strings)[source]

Bases: object

get(str_id, count, few_max=5, varname='count')[source]
Return type

str

class iccas.i18n.lib.TranslationFile(path, content, last_modified)[source]

Bases: object

content: dict
last_modified: int
static load(path)[source]
Return type

TranslationFile

path: pathlib.Path
static read(path)[source]
reload_if_modified()[source]
Return type

bool

class iccas.i18n.lib.TranslationsManager(*paths)[source]

Bases: object

injector(scoped_translations=None)[source]

Decorator that adds a lang argument to the signature and injects a strings argument of type Translation. If the translation files are modified, they are automatically reloaded.

You can also pass extra translations as dict or YAML string to the wrapped function. Nonetheless, any modification will require to reload the module to take effect.

Parameters

scoped_translations (Union[None, str, Mapping[str, Mapping[str, Union[str, Mapping[str, str]]]]]) – yaml string or dictionary

Module contents

iccas.i18n.language(lang)[source]
iccas.i18n.set_language(lang)[source]

Sets the language. Supported languages: Italian (“it”) and English (“en”)

iccas.i18n.set_locale(lang)[source]

Apart from setting the internal language of the package, also sets the locale accordingly so that pandas/matplotlib displays translated dates