composeui.core.translationcheck

Check an app’s catalogs against the text its code translates.

Run it on the app’s main view; it fails on text a catalog misses or on a translation whose {placeholders} differ from the text’s, and lists the entries no code uses:

python -m composeui.core.translationcheck examples.pipeform:PipeMainView

With --write fr, it first adds the text fr.json misses to it, translated as “” for a translator to fill; until then, the text shows as written.

The text is found two ways: the string literals passed to tr or T (or set in a SqliteTable’s refusals) in the source of every view of the main view, and the text the views translate as they show it, which finds text tr gets from a variable, e.g. an enum’s. A table’s refusals are found only in a module of a view.

class composeui.core.translationcheck.CatalogReport[source]

Bases: object

What a catalog lacks, or has too much of, for the text of the code.

path: Path
missing: list[str]

text no catalog translates, or as “”: it shows as written in the code

mismatched: list[tuple[str, str]]

text and translation whose {placeholders} differ: formatting it fails or loses one

unused: list[str]

entries for text the code doesn’t translate, or no longer

property is_ok: bool

Tell whether every text is translated with its placeholders.

__init__(path, missing=NOTHING, mismatched=NOTHING, unused=NOTHING)

Method generated by attrs for class CatalogReport.

Parameters:
Return type:

None

composeui.core.translationcheck.check_main_view(main_view_class)[source]

Check each catalog in main_view_class.translations_dir against the app’s text.

Parameters:

main_view_class (type[MainView])

Return type:

list[CatalogReport]

composeui.core.translationcheck.main(argv=None)[source]

Print a report for each catalog of a main view; 1 if one isn’t ok, else 0.

Parameters:

argv (Sequence[str] | None)

Return type:

int

composeui.core.translationcheck.placeholders(text)[source]

Get the {fields} text formats, or None if it isn’t a valid format.

Parameters:

text (str)

Return type:

set[str] | None