Skip to content

API turboframe.testing.i18n

rafageist edited this page Dec 4, 2026 · 4 revisions

turboframe.testing.i18n

Source: turboframe/testing/i18n.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

Checks of an application's catalogues, for its tests: every function returns what is wrong (an empty list when nothing is), so a test asserts == [] and the failure names each problem.

from turboframe.testing.i18n import catalogue_problems, local_underscore_problems
def test_the_spanish_catalogue():
    assert catalogue_problems(LOCALE / "es/LC_MESSAGES/myapp.po", src=SRC) == []
def test_no_local_underscore():
    assert local_underscore_problems(SRC) == []

A catalogue is right when every text the code marks (_(), N_(), ngettext()) is in it and nothing else is, every entry is translated and not fuzzy, a translation keeps the text's {placeholders} and its ~hotkey~ marks (the hotkey one letter, or a key such as F2), every character takes one cell of the screen, and the compiled .mo says the same as the .po.

Contents

HOTKEY, KEYWORDS, Entry, read_po, marked_msgids, fields, catalogue_problems, hotkey_problems, unique_hotkeys, local_underscore_problems

HOTKEY

'~'

KEYWORDS

('_', 'N_', 'ngettext')

class Entry

class Entry
Entry(ids: tuple[str, ...], strs: tuple[str, ...], fuzzy: bool = False, flags: set[str] = <factory>)

A .po entry: ids is the msgid (and the plural's msgid_plural), strs the translation (one per plural form).

read_po

def read_po(po: Path) -> list[Entry]

The entries of a .po file, without its header. A #, comment (fuzzy) belongs to the entry after it.

marked_msgids

def marked_msgids(src: Path, keywords: Iterable[str] = ('_', 'N_', 'ngettext')) -> set[str]

The texts of src's _(), N_() and ngettext() calls on literals (both of a plural).

fields

def fields(text: str) -> Counter

The {placeholders} of text; for a text that is not a format string (code in it), its braces.

catalogue_problems

def catalogue_problems(po: Path, *, src: Path | None = None, keywords: Iterable[str] = ('_', 'N_', 'ngettext'), compiled: bool = True) -> list[str]

What is wrong with the catalogue po: against the texts src marks (when given), its translations, and (compiled) its .mo.

hotkey_problems

def hotkey_problems(msgid: str, msgstr: str) -> list[str]

A translation keeps the text's ~ marks, and its hotkey is one letter (or a key: F2, Alt+X).

unique_hotkeys

def unique_hotkeys(items: Iterable[str]) -> list[str]

The hotkeys used more than once among items (a menu's or a dialog's labels, ~F~ile).

local_underscore_problems

def local_underscore_problems(src: Path) -> list[str]

Functions that assign _ (x, _ = ...) and also call _("..."): the assignment hides gettext in the whole function, and the call breaks at run time.

Clone this wiki locally