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
|
instantiate global i18n translation callable and language switcher helper |
- class _GetTextBinder[source]
Bases:
Observable
redirect
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_txt
can be used as translation callable, but also to switch the current default language. additionallyget_txt
is 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
Observable
to 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 thecount
parameter (if this argument got specified).kwargs¶ – extra kwargs (e.g.
glo_vars
orkey_suffix
- seeget_f_string()
).
- Return type:
- Returns:
translated text.
-
observers:
- get_txt(text, count=None, language='', loc_vars=None, **kwargs) = <ae.kivy.i18n._GetTextBinder object>
instantiate global i18n translation callable and language switcher helper