LocalisedText
Text in several locales, sent as JSON-LD sends a language map, {"en-GB": "Rye loaf", "fr-FR": "Pain de seigle"}; text.pick reads the entry for a locale.
Text formats; not ordered; since Jadpo 0.1.0.
Make one
It maps Locale to Text: build one from a map of them, as you build a named map type of your own.
Text, JSON and storage
It has no single text form, so text.from and text.parse don't take it. JSON sends an object of its entries, each key written as its text.
| JSON |
|---|
{"en-GB":"Leek soup","fr-FR":"Soupe aux poireaux"} |
{"en-US":"Leek potage"} |
{"de-DE":"Lauchsuppe"} |
{} |
It is stored in one column named for the field, of type jsonb. {"de-DE":"Lauchsuppe"} is stored as '{"de-DE":"Lauchsuppe"}'::jsonb.
Shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"en-GB":"Leek soup","fr-FR":"Soupe aux poireaux"} |
Leek soup |
{"en-US":"Leek potage"} |
Leek potage |
{"de-DE":"Lauchsuppe"} |
Lauchsuppe |
{} |
"" |
Operations
text.pick(value: LocalisedText, locale: Locale) -> Text: The text invalueforlocale: its entry, else the entry of its language (the locale CLDR's likely subtags give for the language first), else the application's default locale's, else the first.
Like every standard type, it also has the contract's own operations: text.format, json.read, json.write and ==. It isn't ordered, so < and sorting don't take it. Every standard type meets one contract says how they work.
Markdown for agents: /docs/types/type-localised-text.md.Built from Jadpo main at e00e61f.