Translations: @t()
Put translations in a locales folder next to the script (or in the site folder): locales/en.json, locales/fr.yaml, or a folder per locale such as locales/de/shop.json, whose keys start with shop..
# locales/fr.yaml
hello: Bonjour, {name} !
cart:
items:
"=0": Votre panier est vide
one: "{count} article"
other: "{count} articles"<locale set="fr" />
<echo>{ @t('hello', { name: $user.name }) }</echo> <!-- Bonjour, Ann ! -->
<echo>{ @t('cart.items', { count: $cart->count() }) }</echo> <!-- 3 articles -->
<echo>{ @format_currency($total, 'EUR') } { @format_date(@today(), 'long') }</echo> <!-- 9,50 € 20 novembre 2026 -->locale(set: 'fr')
echo "{ @t('hello', { name: $user.name }) }" // Bonjour, Ann !
echo "{ @t('cart.items', { count: $cart->count() }) }" // 3 articles
echo "{ @format_currency($total, 'EUR') } { @format_date(@today(), 'long') }" // 9,50 € 20 novembre 2026- Plurals. With a
count,@t()pickszero,one,two,few,manyorotherby the language's own rules. These are the CLDR rules for English, French, Portuguese, Russian, Ukrainian, Polish, Czech, Arabic, Hebrew, Irish, Welsh, Japanese, Chinese, Korean and more. An exact form such as=0wins. - Fallbacks. A missing translation is looked for in
fr-CA, thenfr, then the default locale (enunless set). If it isn't anywhere, you get the key itself, and a warning is logged once under thei18ncategory. - The locale comes from
locale(set: fr), fromlocale(from: …)(the best available match for a list or an Accept-Language header), from$config.i18n.locale, fromKSCRIPT_LOCALE, or from the computer's language.@locale()gives it, and@locales()lists the locales there are files for. A route or middleware that sets the locale draws the@view()it answers with in it, ahead of the language the request asks for, so a site can let its own cookie win over the browser's. - Pages pick it in this order: a path prefix (
/fr/aboutservesabout.htmlin French when there are French translations),?lang=fr, alangcookie, and then the browser's Accept-Language.@locale_path($request.path, 'de')gives the link to the same page in German. The default locale has no prefix. - Formatting. These follow the locale, or one you pass as the last argument:
@format_number(1234.5)gives 1,234.5 or 1 234,5;@format_percent(0.25);@format_currency(9.5, 'GBP');@format_date(date, 'short' | 'medium' | 'long' | 'full' | 'time' | 'datetime' | 'd MMMM yyyy');@format_relative(date, from?)gives 3 hours ago, in 2 days or just now, measured from now unlessfrom:is given;@format_duration(1h30m)gives 1 hour 30 minutes;@format_list(['tea', 'coffee', 'milk'])gives tea, coffee and milk, or tea, coffee or milk withstyle: 'or';@format_ordinal(23)gives 23rd, and 23e in French;@format_bytes($file.size)gives 1.4 MB, or 1.3 MiB withbinary: true.
- Settings:
i18n: { folder: lang, default: en-GB, locale: fr }in config, ortranslations(folder: lang, default: en-GB).@has_t(key)checks whether a key has a translation, and@plural(count)gives the plural category.
The words for relative times, lengths of time, lists and ordinals are built in for English, French, German, Spanish, Italian, Portuguese and Dutch. For another language, or to change them, add these keys to its translation file: time.second up to time.year with plural forms and {count}, time.ago and time.in with {time}, time.now, list.and, list.or, and ordinal with {count}:
# locales/pl.yaml
time:
hour: { one: "{count} godzina", few: "{count} godziny", many: "{count} godzin" }
ago: "{time} temu"