pysepal.i18n.binding.BoundCatalog#

class pysepal.i18n.binding.BoundCatalog(folder, *, strict)[source]#

One message directory, resolved per locale.

Build it through catalog(), which caches one instance per path and strictness. Constructing it directly bypasses that cache.

Load and validate English, and record what the directory ships.

Methods

__init__

Load and validate English, and record what the directory ships.

available_locales

Return the codes this directory ships, English first.

check

Return every translator problem in every shipped locale.

msg

Return one message, rendered in this runtime scope's locale.

Parameters:
  • folder (Path)

  • strict (bool)

BoundCatalog.__init__(folder, *, strict)[source]#

Load and validate English, and record what the directory ships.

Parameters:
  • folder (Path)

  • strict (bool)

Return type:

None

BoundCatalog.available_locales()[source]#

Return the codes this directory ships, English first.

Returns:

The directory names, for MapApp.element(locales=...).

Return type:

Tuple[str, …]

BoundCatalog.check()[source]#

Return every translator problem in every shipped locale.

Returns:

A deterministically sorted tuple, empty when the catalogue is clean. This method never raises: English is validated once at bind time, but a target locale is read lazily, so a load failure – bad JSON, a duplicate key, a leaf that is also a prefix, and the rest of load_locale()’s hard errors – surfaces here as one unreadable_locale problem instead of aborting the loop, so one broken locale cannot hide every other locale’s problems too.

Return type:

Tuple[CatalogProblem, …]

BoundCatalog.msg(key, /, **values)[source]#

Return one message, rendered in this runtime scope’s locale.

This is the only lookup. Reading the locale subscribes when a render is in progress, so a component that calls this – directly, or through an ordinary helper on the same call stack – re-renders when the language changes. Event handlers in the same Solara context read that locale too. A worker without the context reads the process default; return results or message keys to the UI context for translation instead.

key is positional-only, so a message may carry a {key} placeholder passed as key=....

Parameters:
  • key (str) – The dotted message key. May be computed, e.g. from a registry table that holds keys as data.

  • **values (Any) – Placeholder values. count also selects a plural form when key names a plural node in English.

Returns:

The formatted message.

Raises:
  • MissingMessageError – A strict catalogue does not define key.

  • MessageFormatError – A placeholder value was not supplied, count was omitted for a plural key, or the template cannot render.

Return type:

str