API reference
i18n.json
Every field of the shared config file that Rust, the Tauri front end and nuxt-i18n-micro read.
One file next to the locale folder (never inside it: every *.json in the folder root is a locale). Rust reads it
with Builder::config(path) (native, WASI) or Builder::config_json(include_str!(..)) (everywhere); the plugin
sends its data to the WebView in meta; the Nuxt module takes the same fields as options.
i18n.json
{
"defaultLocale": "en",
"fallbackLocale": "en",
"locales": [
{ "code": "en", "iso": "en-US", "displayName": "English" },
{ "code": "de-at", "iso": "de-AT", "fallbackLocale": "de" },
{ "code": "de", "iso": "de-DE" },
{ "code": "ar", "iso": "ar-EG", "dir": "rtl" },
{ "code": "es", "disabled": true }
],
"numberFormats": {
"en": { "currency": { "style": "currency", "currency": "USD" }, "short": { "notation": "compact" } }
},
"datetimeFormats": {
"en": { "short": { "dateStyle": "short" } }
}
}
Top level
| Field | Type | Effect |
|---|---|---|
defaultLocale | string or null | the start locale when nothing else picks one (no saved locale, no match in navigator.languages), and the reference locale of check() |
fallbackLocale | string or null | the global fallback: the weakest layer of every chain, see Fallback |
locales | array | the configured locales, in the order available_locales and locales() list them |
numberFormats | object | named number formats, {"<locale>": {"<name>": {Intl.NumberFormat options}}}, see Formats |
datetimeFormats | object | named date formats, {"<locale>": {"<name>": {Intl.DateTimeFormat options}}}, see Formats |
Other fields are ignored, so a Nuxt config fragment can carry its own options in the same file.
locales[]
| Field | Type | Effect |
|---|---|---|
code | string, required | the locale name: file names (de-at.json), set_locale, the front end's locale |
iso | string | the BCP 47 tag for plurals, formats and case rules (de-AT); without it the code is the tag |
fallbackLocale | string | one more step of this locale's chain: de-at → de → en |
dir | string | ltr, rtl or auto: sent to the front end, which sets <html dir> |
displayName | string | the name in a language switcher; without it the CLDR autonym (language_name: "Deutsch") |
disabled | boolean | hidden from available_locales and locales(); set_locale refuses it (Error::DisabledLocale) |
Rules
- Builder calls win over the file:
.locale(..),.fallback(..),.fallback_for(..),.iso(..). Named formats from.formats(..)/.datetime_formats(..)are added to the file's; a name given again wins. - A wrong type is
Error::Config { path, reason }(locales[].code is missing or empty,locales must be an array); broken JSON isError::Json { path, offset, .. }. - Format options
Intlrejects, or unsupported ones, failbuild()withError::UnsupportedFormat { locale, name, option }. - The time zone is not part of the file:
Builder::time_zone, else the system's (in Tauri, the WebView's).