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

The renderer-side translation-catalog seam over morph's derived message keys (morph::forms::i18n, forms/i18n.hpp). More...

#include <functional>
#include <optional>
#include <string>
#include <string_view>

Go to the source code of this file.

Typedefs

using morph::render::TranslationProvider
 A host-supplied catalog lookup: key/bcp47Locale -> translated text, or std::nullopt on a miss.

Functions

std::string morph::render::resolveText (const TranslationProvider &provider, std::string_view bcp47Locale, const std::optional< std::string > &explicitKey, std::string_view derivedKey, std::string_view schemaLiteral)
 Resolves one display slot's text: explicit key, then derived key, then the schema literal.

Detailed Description

The renderer-side translation-catalog seam over morph's derived message keys (morph::forms::i18n, forms/i18n.hpp).

morph::render is client-side only and never appears on the wire — it is the C++ side of the client-side rendering seam. morph ships this seam and the resolution algorithm below; it defines no translation storage format. A host adapts whatever catalog it already owns (Qt QTranslator/.qm, a JSON bundle, a database) into the one TranslationProvider signature.

Definition in file i18n.hpp.

Typedef Documentation

◆ TranslationProvider

Initial value:
std::function<std::optional<std::string>(std::string_view key, std::string_view bcp47Locale)>

A host-supplied catalog lookup: key/bcp47Locale -> translated text, or std::nullopt on a miss.

A default-constructed (empty) TranslationProvider means "no catalog installed" — resolveText treats it the same as a provider that misses on every key.

Definition at line 27 of file i18n.hpp.

Function Documentation

◆ resolveText()

std::string morph::render::resolveText ( const TranslationProvider & provider,
std::string_view bcp47Locale,
const std::optional< std::string > & explicitKey,
std::string_view derivedKey,
std::string_view schemaLiteral )
inlinenodiscard

Resolves one display slot's text: explicit key, then derived key, then the schema literal.

Tried in order, most specific first:

  1. explicitKey (a host-declared x-i18nKey-derived key), if present;
  2. derivedKey (morph::forms::i18n::fieldKey or one of its siblings);
  3. a miss at both falls back to schemaLiteral — the schema's authored title / description / x-placeholder / group or step title, unchanged. An empty/unset provider ("no catalog installed") skips straight to schemaLiteral, matching an unconfigured renderer's behavior exactly.
    Parameters
    providerThe host's catalog lookup.
    bcp47LocaleThe locale to resolve against (e.g. "fr-FR").
    explicitKeyThe field/group/rule/step's declared x-i18nKey-based key, or std::nullopt when none is declared.
    derivedKeyThe mechanically-derived key for this slot.
    schemaLiteralThe schema's authored fallback text for this slot.
    Returns
    The resolved display text.

Definition at line 65 of file i18n.hpp.