ae.kivy.i18n
ae.kivy.i18n module
this module is adding translatable f-strings to the python and kv code of your app,
via the helper function get_txt() and the _GetTextBinder class.
Module Attributes
- class _GetTextBinder[source]
Bases:
Observableredirect
ae.i18n.get_f_string()to an instance of this class.kivy currently only support a single one automatic binding in kv files for all function names ending with _ (see watched_keys extension in kivy/lang/parser.py line 201; e.g. f_ would get recognized by the lang_tr re pattern, but kivy will only add the _ symbol to watched_keys and therefore f_ not gets bound.) to allow both - f-strings and simple get_text messages - this module binds
ae.i18n.get_f_string()to the get_txt symbol (instead ofae.i18n.get_text()).get_txtcan be used as the translation callable, but also to switch the current default language. additionally,get_txtis implemented as an observer that automatically updates any translations messages of all active/visible kv rules on switch of the language at app run-time.inspired by (see also discussion at https://github.com/kivy/kivy/issues/1664):
- observers: list[tuple[Callable, tuple, dict]] = []
list of bound observer tuples (func, args, kwargs)
- _bound_uid = -1
- fbind(name, func, *args, **kwargs)[source]
override fbind (fast bind) from
Observableto collect and separate _ bindings.
- __call__(text, count=None, language='', loc_vars=None, **kwargs)[source]
translate text into the current-default or the passed language.
- Parameters:
language¶ (
str) – language code to translate the passed text to (def=current default language).loc_vars¶ (
Optional[dict[str,Any]]) – local variables used in the conversion of the f-string expression to a string. the count item of this dict will be overwritten by the value of thecountparameter (if this argument got specified).kwargs¶ – extra kwargs (for example,
glo_varsorkey_suffix- seeget_f_string()).
- Return type:
- Returns:
translated text.