morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
i18n.hpp File Reference

Stable, schema-derived message-key vocabulary for renderer i18n. More...

#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>

Go to the source code of this file.

Enumerations

enum class  morph::forms::i18n::FieldSlot : std::uint8_t { Label , Help , Placeholder }
 Which of a field's three translatable texts a message key names. More...

Functions

constexpr std::string_view morph::forms::i18n::fieldSlotName (FieldSlot slot) noexcept
 The catalog-key suffix for slot.
std::string morph::forms::i18n::withSlot (std::string_view stem, FieldSlot slot)
 Appends .<slotName> to a message-key stem.
std::string morph::forms::i18n::fieldKeyStem (std::string_view actionTypeId, std::string_view wireField)
 The derived message-key stem for a field: <actionTypeId>.<wireField>.
std::string morph::forms::i18n::fieldKey (std::string_view actionTypeId, std::string_view wireField, FieldSlot slot)
 The fully-derived message key for one field text slot.
std::optional< std::string > morph::forms::i18n::explicitFieldKey (std::string_view i18nKeyOverride, FieldSlot slot)
 The explicit override key for one field text slot, when the field declares an x-i18nKey stem override.
std::string morph::forms::i18n::groupKey (std::string_view actionTypeId, std::size_t groupIndex)
 The derived message key for a layout group's title.
std::string morph::forms::i18n::ruleKey (std::string_view actionTypeId, std::size_t ruleIndex)
 The derived message key for a cross-field rule's violation message.
std::string morph::forms::i18n::wizardTitleKey (std::string_view wizardId)
 The derived message key for a wizard's own title.
std::string morph::forms::i18n::wizardStepTitleKey (std::string_view wizardId, std::size_t stepIndex)
 The derived message key for one wizard step's title.
std::string morph::forms::i18n::appTitleKey (std::string_view appId)
 The derived message key for an app shell's own title.
std::string morph::forms::i18n::appMenuLabelKey (std::string_view appId, std::size_t menuIndex)
 The derived message key for one app-menu entry's label.

Detailed Description

Stable, schema-derived message-key vocabulary for renderer i18n.

A renderer that wants to translate a piece of GUI display text (a field's label/help/placeholder, a layout group's title, a cross-field rule's violation message, a wizard's or app-shell's title) needs a stable catalog key to look that text up under. This header is the single source of truth for how such a key is derived from identifiers the schema (or the actionType label a renderer already has, per docs/spec/forms/forms.md's renderer contract) already carries: morph::model::ActionTraits<A>::typeId(), a reflected wire field name, or a 0-based index into a schema array (x-layout.groups, x-rules, a wizard's steps, an app's menu).

No key derived here is written into the schema — a renderer computes it itself from data it already has, so the common (no-override) case adds zero bytes to any schema. See morph::render::resolveText (render/i18n.hpp) for how a derived key is looked up against a host-supplied catalog, with the schema's authored literal text as the fallback on a miss.

Definition in file i18n.hpp.

Enumeration Type Documentation

◆ FieldSlot

enum class morph::forms::i18n::FieldSlot : std::uint8_t
strong

Which of a field's three translatable texts a message key names.

Enumerator
Label 

The field's display label (<stem>.label).

Help 

The field's help/description text (<stem>.help).

Placeholder 

The field's empty-state placeholder text (<stem>.placeholder).

Definition at line 35 of file i18n.hpp.

Function Documentation

◆ fieldSlotName()

std::string_view morph::forms::i18n::fieldSlotName ( FieldSlot slot)
nodiscardconstexprnoexcept

The catalog-key suffix for slot.

Parameters
slotThe field text slot.
Returns
"label", "help", or "placeholder".

Definition at line 44 of file i18n.hpp.

◆ withSlot()

std::string morph::forms::i18n::withSlot ( std::string_view stem,
FieldSlot slot )
inlinenodiscard

Appends .<slotName> to a message-key stem.

Parameters
stemA message-key stem: a derived <actionTypeId>.<wireField> or a host-declared override (a field's x-i18nKey).
slotWhich field text this key names.
Returns
"<stem>.<slotName>".

Definition at line 68 of file i18n.hpp.

◆ fieldKeyStem()

std::string morph::forms::i18n::fieldKeyStem ( std::string_view actionTypeId,
std::string_view wireField )
inlinenodiscard

The derived message-key stem for a field: <actionTypeId>.<wireField>.

Parameters
actionTypeIdActionTraits<A>::typeId() of the action the field belongs to.
wireFieldThe field's wire key (its reflected member name).
Returns
The stem, before the .label / .help / .placeholder suffix.

Definition at line 79 of file i18n.hpp.

◆ fieldKey()

std::string morph::forms::i18n::fieldKey ( std::string_view actionTypeId,
std::string_view wireField,
FieldSlot slot )
inlinenodiscard

The fully-derived message key for one field text slot.

Parameters
actionTypeIdActionTraits<A>::typeId() of the action the field belongs to.
wireFieldThe field's wire key.
slotWhich of the field's texts this key names.
Returns
"<actionTypeId>.<wireField>.<slot>".

Definition at line 91 of file i18n.hpp.

◆ explicitFieldKey()

std::optional< std::string > morph::forms::i18n::explicitFieldKey ( std::string_view i18nKeyOverride,
FieldSlot slot )
inlinenodiscard

The explicit override key for one field text slot, when the field declares an x-i18nKey stem override.

A single FieldMeta::i18nKey override (see gui_field_metadata.md) replaces the derived <actionTypeId>.<wireField> stem for all three of a field's text slots; the .label / .help / .placeholder suffix is still appended per slot, exactly as it is for the derived key.

Parameters
i18nKeyOverrideThe field's declared FieldMeta::i18nKey (empty = no override).
slotWhich of the field's texts this key names.
Returns
std::nullopt when i18nKeyOverride is empty; otherwise "<i18nKeyOverride>.<slot>".

Definition at line 105 of file i18n.hpp.

◆ groupKey()

std::string morph::forms::i18n::groupKey ( std::string_view actionTypeId,
std::size_t groupIndex )
inlinenodiscard

The derived message key for a layout group's title.

Parameters
actionTypeIdActionTraits<A>::typeId() of the action the group belongs to.
groupIndexThe group's 0-based index into x-layout.groups.
Returns
"<actionTypeId>.group.<groupIndex>".

Definition at line 116 of file i18n.hpp.

◆ ruleKey()

std::string morph::forms::i18n::ruleKey ( std::string_view actionTypeId,
std::size_t ruleIndex )
inlinenodiscard

The derived message key for a cross-field rule's violation message.

Parameters
actionTypeIdActionTraits<A>::typeId() of the action the rule belongs to.
ruleIndexThe rule's 0-based index into x-rules.
Returns
"<actionTypeId>.rule.<ruleIndex>".

Definition at line 127 of file i18n.hpp.

◆ wizardTitleKey()

std::string morph::forms::i18n::wizardTitleKey ( std::string_view wizardId)
inlinenodiscard

The derived message key for a wizard's own title.

Parameters
wizardIdThe registered wizard id.
Returns
"<wizardId>.title".

Definition at line 137 of file i18n.hpp.

◆ wizardStepTitleKey()

std::string morph::forms::i18n::wizardStepTitleKey ( std::string_view wizardId,
std::size_t stepIndex )
inlinenodiscard

The derived message key for one wizard step's title.

Parameters
wizardIdThe registered wizard id.
stepIndexThe step's 0-based index.
Returns
"<wizardId>.step.<stepIndex>.title".

Definition at line 147 of file i18n.hpp.

◆ appTitleKey()

std::string morph::forms::i18n::appTitleKey ( std::string_view appId)
inlinenodiscard

The derived message key for an app shell's own title.

Parameters
appIdThe registered app id.
Returns
"<appId>.title".

Definition at line 158 of file i18n.hpp.

◆ appMenuLabelKey()

std::string morph::forms::i18n::appMenuLabelKey ( std::string_view appId,
std::size_t menuIndex )
inlinenodiscard

The derived message key for one app-menu entry's label.

Parameters
appIdThe registered app id.
menuIndexThe menu entry's 0-based index.
Returns
"<appId>.menu.<menuIndex>.label".

Definition at line 168 of file i18n.hpp.