Skip to content
ERPForAll DocsDevelopment

    Translated fields

    Char, Text and Html declarations accept .translate(true) or #[field(translate = true)]. Stored values use JSONB language maps. A translated field cannot also be company-dependent; computed and related translated fields remain refused by ORM construction.

    Scalar reads (value, values, read, web_read, exports and grouped reads) project the context language with en_US fallback. Unset/empty language selects en_US. Non-default languages must be active. Search filters and ordering use the same language projection, including a many2one comodel’s order in grouped reads. Malformed or oversized language codes are refused before query shapes are cached or SQL is generated.

    prefetch_langs=true keeps scalar reads as strings. The transaction cache already retains the whole stored map, allowing subsequent language reads from that cache. Use the explicit typed Records::get_field_translations(tx, field) accessor to obtain erp_fields::FieldTranslations: get(lang) returns the stored entry without fallback; iter, len, is_empty and into_inner provide ordinary map access. NULL returns an empty map. Model, field and record access checks still apply. Corrupt maps fail with a Programming error naming the model and field.

    Records::update_field_translations(tx, field, entries) updates named translations and returns whether it changed the value. Strings set entries; Value::False, Value::Bool(false) and Value::Json(JSON null) remove named non-English entries. Falsy English updates are ignored, even for required fields; an empty string remains a real update and is allowed only on an optional English base. Other values are refused. The final duplicate entry determines the request; a final falsy English entry cancels an earlier English update in that request. Empty input changes nothing. The English no-op follows the designated lead’s correction to SEARCH r1 M2.

    A scalar write of False clears the whole field. A scalar string writes the context language; when English is inactive, the base stays synchronized with the written language. Copy preserves the whole translation map. Required translated fields require a non-empty English base. The check runs when the record is saved (create and write). An onchange works on a draft, so a new record’s first onchange succeeds while a required translated field is still empty.

    Static selection fields store untranslated key strings on business records, but their human-readable labels can be translated per language via ir.model.fields.selection (ADR 0002, SPEC-FIELD-105).

    1. Reflection & Registration: Static selection fields declared on models are automatically reflected into ir_model_fields_selection during registry reflection (erp_orm::reflection::reflect_models). Each selection value creates an external ID in ir_model_data formatted as <module>.selection__<model_ident>__<field>__<value_ident>.

    2. PO Catalog Format: Translations in PO files target the selection label using standard model references:

      #: model:ir.model.fields.selection,name:<module>.selection__<model_ident>__<field>__<value_ident>
      msgid "Source Label"
      msgstr "Translated Label"
    3. Runtime Resolution:

      • fields_get and describe project translated labels for context['lang'], falling back to en_US or source labels if untranslated.
      • Keys and item order remain immutable; only the display label is localized.
      • At the ORM API level, Transaction::selection_labels(model, field) and Transaction::selection_labels_for_lang(model, field, lang) resolve the localized pairs in order.