Osy#betaRun it on Osyrin: osyrin.com

Reference / I18n

app.SourceLanguage — the language the app is written in

app.SourceLanguage = "es";

`app.SourceLanguage = "es";` says the app's own text is written in Spanish. The page's `<html lang>` then says `es` when no translation is served, `App.Languages` starts with `es`, and English is offered only when the app ships its own English file (`locales/en.osy`). Without it an app is written in English, as before.

stable2 examples compiled by CIi18nlanguageconfig

Summary#

An app's own words — every Text("…"), label, title and message in its source — are written in one language. That is English unless the app says otherwise, once, beside its culture:

app.SourceLanguage = "es";      // the words in this app's source are Spanish
app.DefaultCulture = "es-ES";   // …and numbers, money and dates are formatted the Spanish way

Signature#

app.SourceLanguage = "<language tag>";   // "es", "sv", "de", "pt-BR" — a string literal; default "en"

A value that is not a language tag in a string is a compile error at its line, in osy validate and the compile alike.

Description#

What it changes.

without itapp.SourceLanguage = "es"
<html lang> when no translation is servedenes
App.Languages["en", …translations]["es", …translations]
a browser that asks for Englishis given the source text, labelled enis given the source text, labelled es — unless the app ships English
Session.Language with nothing chosenenes
a [Translatable] value read in this languagethe stored valuethe stored value (it is the source)

English is a translation like any other. An app written in Spanish speaks only Spanish until it ships its own English words — translations en { … }, usually in locales/en.osy (A language's words — locales/<language>.osy). Then English is offered, chosen by the browser, the reader's own [PreferredCulture] or a switch exactly as any other language is (Which language a reader gets — and switching it).

A kit's words in the source language. The kits are written in English. A Spanish app that wants their buttons and messages in Spanish translates them in its own locales/es.osy (osy translate writes the entries, marked with each kit's name). Those are used whenever the reader's language is the source.

Not the culture. app.DefaultCulture decides how numbers, money and dates are written (Culture formatting — ToString(format, culture)); app.SourceLanguage decides which language the words are. A Spanish app usually sets both.

Examples#

app.SourceLanguage = "es";

[Route("/")]
[AllowAnonymous]
component Inicio() {
  render {
    Stack(gap: 2) {
      Text("Tu cesta está vacía.");
      Text(Session.Language);          // "es" — the source, until the app ships another language
    }
  }
}
app.SourceLanguage = "es";

[Route("/")]
[AllowAnonymous]
component Inicio() { render { Text("Tu cesta está vacía."); } }

translations en {
  text "Tu cesta está vacía." => "Your bag is empty.";
}

See also#

Related

Which language a reader gets — and switching it

A reader's language is, in order: their explicit choice (a `/sv/` address prefix or a language switch), their own…

A language's words — locales/<language>.osy

A project's translations are checked-in source: one `locales/<language>.osy` per language, a `translations sv { }`…

Culture formatting — ToString(format, culture)

Format numbers, currency, percentages and dates for a declared culture — `total.ToString("C", "sv-SE")` → `1 234,56…

[Translatable] — an entity's own words in every language

`[Translatable]` on a stored `string` member keeps a translation per language, in a table beside its entity. Code…