composeui.core.translation

Translate the text views show, from JSON catalogs.

A catalog is a <language>.json file mapping the text as written in the code to its translation: {"Radius": "Rayon"}. Text missing from every catalog is shown as written, like text translated as “”: a translation still to fill.

composeui.core.translation.T

text to translate, as written in the code, wherever it’s declared: add: ButtonView = child(ButtonView, text=T("Add"))

class composeui.core.translation.TranslatedText[source]

Bases: str

Text View.tr translated, remembering it as written to translate it again.

MainView.set_language translates it again wherever a view keeps it: in a field, a list (a table’s headers) or a dict’s keys (a choice’s labels). Formatting it keeps the arguments, to format the next translation with them. Other str methods return a plain str, which stays in its language.

Built from text alone (as T), it is the text as written. It is translated once a view keeps it and the main view sets a language. Use it for text declared where no view can tr it, e.g. a field’s default or a class variable.

source: str
arguments: tuple[tuple[Any, ...], dict[str, Any]] | None

the format arguments, or None if it isn’t formatted

static __new__(cls, text, source=None, arguments=None)[source]
Parameters:
Return type:

Self

format(*args, **kwargs)[source]

Format it, remembering the arguments: translated text among them follows too.

Parameters:
Return type:

TranslatedText

translated(translate)[source]

Translate it again, with translate.

Parameters:

translate (Callable[[str], str])

Return type:

TranslatedText

composeui.core.translation.translator(language, directories)[source]

Get the translation into language from the catalogs in directories.

The first directory with a translation of a text wins: an app’s catalogs, listed before ComposeUI’s, can change the text of ComposeUI’s views.

Parameters:
  • language (str)

  • directories (Sequence[Path])

Return type:

Translate