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

FieldTypeEffect
defaultLocalestring or nullthe start locale when nothing else picks one (no saved locale, no match in navigator.languages), and the reference locale of check()
fallbackLocalestring or nullthe global fallback: the weakest layer of every chain, see Fallback
localesarraythe configured locales, in the order available_locales and locales() list them
numberFormatsobjectnamed number formats, {"<locale>": {"<name>": {Intl.NumberFormat options}}}, see Formats
datetimeFormatsobjectnamed 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[]

FieldTypeEffect
codestring, requiredthe locale name: file names (de-at.json), set_locale, the front end's locale
isostringthe BCP 47 tag for plurals, formats and case rules (de-AT); without it the code is the tag
fallbackLocalestringone more step of this locale's chain: de-at → de → en
dirstringltr, rtl or auto: sent to the front end, which sets <html dir>
displayNamestringthe name in a language switcher; without it the CLDR autonym (language_name: "Deutsch")
disabledbooleanhidden 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 is Error::Json { path, offset, .. }.
  • Format options Intl rejects, or unsupported ones, fail build() with Error::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).