Guides
Locale files
The JSON format, the folder layout with root and page files, and i18n.json.
The files are the same as in nuxt-i18n-micro: a Nuxt site and a Rust app can share the folder.
Format
A locale file is a JSON tree of any depth. A key is the path joined with dots.
locales/en.json
{
"nav": { "home": "Home", "settings": "Settings" },
"cart": { "summary": "{name} has {count} item | {name} has {count} items" },
"pair": "{0} and {1}",
"list": ["first", "second"]
}
| Rule | Example |
|---|---|
| Nested objects become dotted keys | nav.home |
| A literal flat key beats walking the tree | "a.b": "x" wins over { "a": { "b": "y" } } |
| Array items are addressed by index | list.0 |
null means "no value" | the lookup goes on to the next layer |
| Numbers and booleans read as JS prints them | true → "true" |
| A subtree is not a message | t("nav") returns "nav" |
| Duplicate keys: the last one wins |
A broken file stops build() with an error that names it:
match I18n::builder().dir("locales").build() {
Err(i18n_next::Error::Json { path, offset, .. }) => eprintln!("{path}: byte {offset}"),
other => { /* … */ }
}
Layout
locales/
en.json root file of en
de.json
pages/settings/en.json page "settings"
pages/user/profile/en.json page "user-profile"
i18n.json config, next to the folder
locales/<locale>.jsonis the root: menus, buttons, errors, tray. Every page sees it.locales/pages/<a>/<b>/<locale>.jsonis the pagea-b, as in Nuxt. A page reads its own keys first, then the root (Pages).- Other nested files are ignored.
Where the files come from (a folder, embedded bytes, the network) is up to you: see Loading.
i18n.json
One config for Rust, the Tauri frontend and Nuxt. Keep it next to the locale folder, not inside: every
*.json in the folder root is read as a locale.
i18n.json
{
"defaultLocale": "en",
"fallbackLocale": "en",
"locales": [
{ "code": "en", "iso": "en-US", "displayName": "English" },
{ "code": "de-at", "iso": "de-AT", "fallbackLocale": "de" },
{ "code": "ar", "iso": "ar", "dir": "rtl" },
{ "code": "es", "disabled": true }
],
"numberFormats": { "en": { "currency": { "style": "currency", "currency": "USD" } } },
"datetimeFormats": { "en": { "short": { "dateStyle": "short" } } }
}
Read it with .config("i18n.json") or .config_json(include_str!("../i18n.json")). Builder calls (locale,
fallback, fallback_for, iso) override the file. i18n.locales() lists the enabled locales
(LocaleInfo { code, iso, dir, display_name }). Every field: i18n.json.