cadrumo.domain.calculations.registry.modelo_localization module

Canonical locale-key identity and scalar resolution for Modelo schemas.

class ModeloLocalizationFieldKind(*values)[source]

Bases: StrEnum

Which localizable text a modelo locale key addresses.

LABEL
HELP
TITLE
OFFICIAL_NAME
CasillaLocalizationField

The fields a CASILLA carries, which are only its label and its help text.

A narrowing written out twice before this existed. A casilla has no title and no official name – those belong to the modelo and its revision – so keeping this narrow stops a caller asking for a casilla key that can never resolve.

alias of Literal[LABEL, HELP]

encode_modelo_locale_segment(value)[source]

Encode one dynamic identity as an injective dotted-key segment.

Return type:

str

Parameters:

value (str)

modelo_locale_key(modelo_id, field)[source]

Derive a Modelo-level presentation key.

Return type:

str

Parameters:
  • modelo_id (str)

  • field (Literal['title', 'official_name'])

revision_locale_key(modelo_id, revision_id, field=ModeloLocalizationFieldKind.LABEL)[source]

Derive a revision-level presentation key.

Return type:

str

Parameters:
  • modelo_id (str)

  • revision_id (RevisionId)

  • field (Literal[ModeloLocalizationFieldKind.LABEL])

construct_locale_key(modelo_id, revision_id, construct_id, field='title')[source]

Derive the edition-scoped presentation key for one construct.

Return type:

str

Parameters:
  • modelo_id (str)

  • revision_id (RevisionId)

  • construct_id (str)

  • field (Literal['title'])

construct_lineage_locale_key(modelo_id, construct_id, field='title')[source]

Derive the modelo-wide key a construct’s title shares across the editions that keep its id.

A construct id is the identity keyed-family inheritance carries from one edition to the next, so it plays the role continuidad_id plays for a casilla: the tier below the edition key where text every edition agrees on is stored once.

Return type:

str

Parameters:
casilla_occurrence_locale_key(modelo_id, revision_id, casilla_id, field)[source]

Derive the exact revision-occurrence key for one casilla field.

Return type:

str

Parameters:
  • modelo_id (str)

  • revision_id (RevisionId)

  • casilla_id (str)

  • field (Literal[ModeloLocalizationFieldKind.LABEL, ModeloLocalizationFieldKind.HELP])

casilla_continuity_locale_key(modelo_id, continuidad_id, field)[source]

Derive the stable continuity key for one grounded casilla field.

Return type:

str

Parameters:
  • modelo_id (str)

  • continuidad_id (str)

  • field (Literal[ModeloLocalizationFieldKind.LABEL, ModeloLocalizationFieldKind.HELP])

casilla_alias_locale_key(modelo_id, revision_id, casilla_id, alias_id, field=ModeloLocalizationFieldKind.LABEL)[source]

Derive the presentation key for one casilla alias occurrence.

Return type:

str

Parameters:
  • modelo_id (str)

  • revision_id (RevisionId)

  • casilla_id (str)

  • alias_id (str)

  • field (Literal[ModeloLocalizationFieldKind.LABEL])

as_toml_array(value)[source]

Narrow a frozen TOML array to object entries, or return None.

Return type:

tuple[object, ...] | None

Parameters:

value (object)

enroll_revision_localization(*, modelo_id, revision_id, raw_revision)[source]

Attach derived locale identities without copying presentation values.

Return type:

dict[str, object]

Parameters:
resolve_modelo_localization(keys, *, locale, year=None)[source]

Resolve exact/variant keys, then continuity, with Spanish fallback.

keys is ordered from most-specific to least-specific. The requested locale is exhausted before the same identity chain is resolved through the mandatory Spanish source. No non-Spanish locale can become another non-Spanish locale’s fallback.

Resolution advances on the absence of a VALUE, never on the absence of a key. That distinction is the whole reason the less-specific tiers can fire: the locale scaffold emits an occurrence key for every casilla in every revision, null until translated, and exempts those nulls from the untranslated-string honesty ratchet. So the first key in the chain always exists. A chain that stopped at key EXISTENCE therefore stopped at index zero every time, for every casilla in every revision, and the continuity tier below it was written, scaffolded and never once consulted.

The stop it used to perform was meant to let a revision deliberately blank an inherited label, but the catalogue cannot express that intent: an explicit null and a scaffolded-but-untranslated null are the same bytes, so the stop could only ever suppress translations nobody chose to suppress. Restoring the override needs a way to say “blanked on purpose” in the data, not a stop that fires on every untranslated key.

A requested locale is read only down to the tier at which Spanish resolves. Catalogues store a value at the least specific key that yields the same text, so a Spanish value on a more specific key marks text that differs from the lineage-wide one; a translation stored below that tier translates the other text, and serving it would render a different meaning. Past that barrier the Spanish value itself is returned.

Return type:

str | None

Parameters:
modelo_localization_source(keys, *, locale, lookup=None)[source]

Return the (key, locale) that serves a chain, or None when nothing does.

This is the selection resolve_modelo_localization() renders, exposed for consumers that report which catalogue coordinate supplied a text. lookup replaces the shared catalogue read, so catalogue tooling can evaluate a proposed catalogue with exactly the runtime selection rule.

A translation renders the Spanish source, so it is read only at the tier where Spanish text resolves or a more specific one. A chain with no Spanish text has nothing to translate and is served by no locale.

Return type:

tuple[str, str] | None

Parameters:
  • keys (tuple[str, ...])

  • locale (str)

  • lookup (LocalizationLookup | None)

require_modelo_localization(keys, *, locale, year=None)[source]

Resolve a label that must exist, refusing an untranslated identity chain.

The same resolution order as resolve_modelo_localization(); the difference is the contract on absence. A construct title, official modelo name, or revision member label has no honest empty rendering, so an unresolved chain is a MissingTranslationError rather than None for the caller to interpret.

Return type:

str

Parameters: