Localization
· One min read
strings/<locale>.toml, one file per language, and strings::tr to read
one with the right plural form.
What landed
- Files. A key maps to a string, or to the plural forms of one.
{name}in a string is replaced by the argument calledname, and annargument also picks the plural form the locale's language calls for. - Fallback. A key missing from the current locale is looked for in the project's fallback locale, one step, not a chain. Missing from both, the key itself comes back — visible in the game rather than blank, because a missing string is a bug to notice and an empty label is a bug to miss.
- Switching.
strings::set_locale,strings::localesfor what the project ships, andstrings::system_localefor what the OS says.
# 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.
