Skip to content

Search

Tilbage
· 1 min. læsning

Localization

One TOML file per language under strings/, plural forms picked by the locale's rules, a fallback locale, and a missing key that shows itself.

Strings live in one TOML file per language under strings/. Plural forms follow the locale's rules, there is a fallback locale, and a missing key comes back as the key.

  • A key maps to a string, or to its plural forms. {name} in a string is replaced by the argument called name, and an n argument picks the plural form by the locale's rules.
  • A key missing from the current locale is looked up in the project's fallback locale, one step. Missing from both, the key itself comes back.
  • strings::set_locale switches, strings::locales lists the project's locales, and strings::system_locale reads the OS locale.
# strings/en.toml
"menu.play" = "Play"
"menu.items" = { one = "{n} item", other = "{n} items" }
let label = strings::tr("menu.items", #{ n: 3 });   // "3 items"

The strings module is in the script modules reference.