For a person or a model about to write an app; a model gets the same text from oad guide.

Contents

Texts in several languages#

An app can carry its own texts in several languages, in one table: localization. Each person sees the app in the language they read, when the app has it, and in its default language otherwise. Nothing translates for you: you write every text in every language, and the checks and tools count what is missing. The host's own words (its buttons, its permission sheet) stay as they are.

When to add a table#

Add localization when the person asks for an app in a language other than English, or for readers of more than one language. The smallest table is the default language alone. It says which language the app's plain texts are in, and so which way they read: an app written in Arabic, Hebrew, Persian or Urdu reads right to left only when it says so.

JSON

[ { "op": "add", "path": "/localization", "value": { "default": "en" } } ]

default is a language tag: two or three lower-case letters, then optionally a script of four letters and a region of two capitals or three digits, such as "en", "ar", "pt-BR", "zh-Hant", "sr-Latn". Write "zh" and "sr" with their script.

A table of texts#

strings holds a table for each language, and one for default. The default table is complete: every key the app names is there. Each key maps to the text in that language. This is the whole table of the example guests:

JSON

{
  "default": "en",
  "strings": {
    "en": {
      "appName": "Guest book",
      "appDescription": "Guests sign with their name, and everyone sees who signed and how many.",
      "signedDescription": "The names of everyone who signed.",
      "lastDescription": "The name of the guest who signed last.",
      "signDescription": "Sign the guest book with a name.",
      "nameDescription": "The name to sign with.",
      "nameMissing": "Write your name first.",
      "yourName": "Your name",
      "sign": "Sign",
      "welcome": "Welcome, {name}!",
      "signatures": "Signatures",
      "empty": "Nobody has signed yet.",
      "count": { "by": "count", "forms": { "=0": "No guests yet.", "one": "{count} guest has signed.", "other": "{count} guests have signed." } }
    },
    "ar": {
      "appName": "دفتر الزوار",
      "appDescription": "يوقّع الضيوف بأسمائهم، ويرى الجميع من وقّع وكم عددهم.",
      "signedDescription": "أسماء كل من وقّع.",
      "lastDescription": "اسم آخر ضيف وقّع.",
      "signDescription": "التوقيع في دفتر الزوار باسم.",
      "nameDescription": "الاسم الذي يُوقَّع به.",
      "nameMissing": "اكتب اسمك أولًا.",
      "yourName": "اسمك",
      "sign": "وقّع",
      "welcome": "أهلًا بك يا {name}!",
      "signatures": "التوقيعات",
      "empty": "لم يوقّع أحد بعد.",
      "count": { "by": "count", "forms": { "=0": "لا ضيوف بعد.", "one": "وقّع ضيف واحد.", "two": "وقّع ضيفان.", "few": "وقّع {count} ضيوف.", "many": "وقّع {count} ضيفًا.", "other": "وقّع {count} ضيف." } }
    },
    "ja": {
      "appName": "ゲストブック",
      "appDescription": "ゲストが名前を書いて記帳し、誰が何人記帳したかを全員が見られます。",
      "signedDescription": "記帳した全員の名前。",
      "lastDescription": "最後に記帳したゲストの名前。",
      "signDescription": "名前を書いてゲストブックに記帳します。",
      "nameDescription": "記帳する名前。",
      "nameMissing": "先に名前を書いてください。",
      "yourName": "お名前",
      "sign": "記帳する",
      "welcome": "ようこそ、{name}さん!",
      "signatures": "記帳した人",
      "empty": "まだ誰も記帳していません。",
      "count": { "by": "count", "forms": { "=0": "まだゲストはいません。", "other": "{count}人のゲストが記帳しました。" } }
    }
  },
  "notes": {
    "welcome": "Shown after a guest signs. {name} is the name they wrote.",
    "count": "Below the list. {count} is how many guests signed."
  }
}
  • Keys start with a letter and hold letters, digits, "_" and ".", at most 80 characters, such as "appName" or "cart.empty". A dot only groups names for a reader. Name a key for what the text is for, not for its words.
  • Blanks. "{name}" in a text is filled with the value passed for name. Write "{{" for a brace the person sees, and "}}" for its pair; any other brace is an error. A translation may leave a blank out, but never adds one the default text lacks.
  • Forms choose a text by a value: by names the blank, forms maps each case to a text, and other is required. For a number: "=0" and any exact number first, then the plural category of the language (one, two, few, many, zero), then other. For a text or a true or false value: the form of that name, else other. Each language writes its own forms: Arabic above has six where English has three, and a language may write one plain text where another needs forms.
  • Notes are for whoever translates later: what the text is for, what each blank holds. Nobody using the app sees them.

Using a text from an expression#

Wherever an expression stands, t gives the text of a key in the language shown, with its blanks filled. The first argument is the key, written as it is; the second is a map of the blank values:

EXPR

t('welcome', { name: 'Ana' })
t('count', { count: size(state.signed) })
t('signatures')

Pass exactly the blanks the default text has, and for forms the by blank too. A number is written for the person's region, as formatNumber writes it. Write one entry with blanks for a whole sentence: never join pieces of translated text with + or a template, since languages put words in other orders.

Fixed places#

A few places never hold an expression: meta.name and meta.description, a grant request's reason, the description of a capability, role, state entry, action, input field, type, rule, flow, flow state and code module, a type's title, an asset's credit, and the agent surface's instructions and tool descriptions. There, a value that is exactly "=t('key')" (single quotes, no spaces, no second argument) shows the text of that key:

JSON

{
  "description": "=t('signDescription')",
  "input": { "name": { "type": "string", "description": "=t('nameDescription')" } },
  "require": [ { "that": "size(trim(input.name)) > 0", "message": "=t('nameMissing')" } ],
  "steps": [
    { "append": "state.signed", "value": "=trim(input.name)" },
    { "set": "state.last", "to": "=trim(input.name)" }
  ]
}

The text a fixed place names is a plain text in every language: no blanks, no forms, not empty. A key with a blank there is refused:

JSON

"=t('welcome')"

Adding a language#

Add a whole language in ONE operation, with a text for every key of the default table:

JSON

[
  { "op": "add", "path": "/localization/strings/fr", "value": {
    "appName": "Livre d'or",
    "appDescription": "Les invités signent de leur nom, et chacun voit qui a signé et combien.",
    "signedDescription": "Les noms de tous ceux qui ont signé.",
    "lastDescription": "Le nom du dernier invité qui a signé.",
    "signDescription": "Signer le livre d'or avec un nom.",
    "nameDescription": "Le nom avec lequel signer.",
    "nameMissing": "Écrivez d'abord votre nom.",
    "yourName": "Votre nom",
    "sign": "Signer",
    "welcome": "Bienvenue, {name} !",
    "signatures": "Les signatures",
    "empty": "Personne n'a encore signé.",
    "count": { "by": "count", "forms": { "=0": "Aucun invité pour l'instant.", "one": "{count} invité a signé.", "other": "{count} invités ont signé." } }
  } }
]

An add at a language's path REPLACES that whole table. To add or change one text, write at the key's own path, such as "/localization/strings/ar/sign". To give an app with no table its first languages, add localization with the default table, then point each place at a key.

Adding a key#

Add the key to the default table first, then to every other table, and use it, in one patch. It also chooses a text by a true or false value:

JSON

[
  { "op": "add", "path": "/localization/strings/en/thanks", "value": { "by": "first", "forms": { "true": "You are the first guest!", "other": "Thank you for signing." } } },
  { "op": "add", "path": "/localization/strings/ar/thanks", "value": { "by": "first", "forms": { "true": "أنت أول ضيف!", "other": "شكرًا لتوقيعك." } } },
  { "op": "add", "path": "/localization/strings/ja/thanks", "value": { "by": "first", "forms": { "true": "最初のゲストです!", "other": "記帳ありがとうございます。" } } },
  { "op": "add", "path": "/surfaces/visual/views/home/body/children/-", "value": { "control": "core:text", "when": "state.last != null", "props": { "value": "=t('thanks', { first: size(state.signed) == 1 })" } } }
]

A key only in a translation is never shown: every key the app names is in the default table.

A language may stay partial#

A language may lack texts: a person shown it reads those in another of the app's languages, along a chain that ends at the default. The checks and tools count what each language lacks (localization.untranslated). A regional table holds only what differs: a table "es-MX" beside "es" gives a reader in Mexico its own words and takes the rest from "es".

Direction, numbers and dates#

The language shown decides everything else: Arabic, Hebrew, Persian and Urdu read right to left, and numbers, dates and plural forms follow the language with the person's region. A chart's plot, a diagram's layout and a canvas never turn. "=env.language" names the language shown and "=env.direction" its direction, for the rare rule that needs them.

Looking as a reader of a language#

The look shows the app as a person of en-US by default. Give it the languages of the person to look as, the way a browser lists them, and read its line "language:" (the language shown, which way it reads, the locale of numbers and dates, and the languages the app carries):

look_at_app   { "name": "guests", "languages": ["ar-EG"] }
language: ar for a reader of ar-EG, right to left, numbers and dates written for ar-EG; the app carries en (default), ar, ja

Look as a reader of each language the app carries. A whole read of the app shows the default table and names the others after the JSON; read one with its pointer, such as "/localization/strings/ar".

What the checks say#

Code What it means What to do
localization.tagInvalid A tag is not written as a language tag. Use the spelling the message gives, such as "en-US" for "en_us".
localization.defaultMissing strings has no table for default. Add that table, or change default.
localization.entryInvalid A text has a lone brace, or forms lack other or have a bad case. Write "{{" for a brace; give other; write numbers as "=1".
localization.keyUnknown A t or a fixed place names a key the default table lacks. Add the key to the default table, or use one the message suggests.
localization.valuesMismatch A t passes other blanks than the default text has. Pass every blank of the default text and its by, and nothing else.
localization.blankUnknown A translation uses a blank the default text lacks. Use the default's blanks only.
localization.fixedNeedsPlainText A fixed place names a text with blanks or forms, or an empty one. Point it at a plain text.
localization.untranslated A language lacks texts for some keys. Translate them, or leave them on purpose.
localization.keyNotInDefault A translation or a note has a key the default lacks. Add it to the default, or remove it.
localization.keyUnused A key of the default table is named nowhere. Use it, or remove it from every table.
localization.sameAsDefault A translation is word for word the default text. Translate it, or remove it.
localization.scriptUnclear "zh" or "sr" without a script. Write "zh-Hans", "zh-Hant", "sr-Cyrl" or "sr-Latn".
localization.fixedTextForm A fixed place is written like a reference but is not exactly one, such as "=t('key', {})". Write it as "=t('key')".
localization.directionUndeclared Most texts read right to left, and the app declares no language. Add localization with its default.
localization.languagesBeyondFloor, localization.keysBeyondFloor, localization.textBeyondFloor More than 64 languages, 2,000 keys in one, 2,000 characters in a text or 24 forms. Keep within: some hosts take no more.

Next#

  • views and controls for the places a text is shown; changing for patches; mistakes for the errors met most.
  • The example Front desk (front-desk.oad.json, a playground sample): a whole app in English, Arabic and Japanese.