aeat.locales.manager module¶
Locale file management: loading, scaffolding, and structural health checks.
LocaleManager owns codebase translation-key discovery and locale YAML
updates. StrictUniqueKeyLoader enforces parse-time duplicate-key
rejection, while LocaleNode documents the recursive locale-tree shape
shared by the manager and parity tests.
- exception LocaleError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
AeatErrorRaised on locale management and parsing errors.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- class StrictUniqueKeyLoader(stream)[source]¶
Bases:
SafeLoaderYAML loader that raises an error on duplicate keys.
- construct_mapping(node, deep=False)[source]¶
Construct a mapping node, raising
LocaleErroron duplicate keys.- Parameters:
node (
MappingNode) – The YAML mapping node to construct.deep (
bool) – Whether to construct values recursively before returning.
- Return type:
- Returns:
A plain
dictof the mapping’s key-value pairs.- Raises:
LocaleError – When a duplicate key is found in the mapping node.
- class LocaleManager(src_dir, locales_dir)[source]¶
Bases:
objectAPI for managing locale files, scaffolding, and structural health.
- get_codebase_keys()[source]¶
Extract all concrete dotted translation keys from the codebase.
Combines three discovery paths:
Regex scanner —
tr("…")/t("…")literal call sites.AST scanner — programmatic emissions such as
WizardValidationError("wizard.errors.select_unknown"),message_key=kwargs, andbuild_entryportal keys.F-string registry — bounded f-string patterns whose value sets are fully known at import time (e.g. wizard choice labels keyed by enum values). See
locales._fstring_registry.
Dynamic namespaces (open-ended f-string and concatenation forms) are returned by
get_codebase_namespaces()and checked through a separate parity assertion that verifies at least one concrete locale key exists under each declared prefix.
- get_codebase_namespaces()[source]¶
Extract dynamic-namespace markers (
<prefix>.*) from the codebase.Returns every prefix discovered through f-string or string concatenation patterns whose tail is computed at runtime. Each marker passes the parity check when at least one concrete locale key starts with its prefix.
- get_yaml_keys(d, current_path='')[source]¶
Recursively extract all dot-notated keys from a nested dictionary.
- scaffold()[source]¶
Parse codebase, generate locale files, auto-sort, and prune extra keys.
- Return type: