Getting started

Quick start

Install the crate, the Tauri plugin and the npm package, then a minimal Rust and a minimal Tauri + Vue app.

Install

Cargo.toml
[dependencies]
i18n-next = "0.1"

Rust 1.90 or newer, edition 2024. Features worth knowing (all of them: Features):

FeatureDefaultWhat
formatyesnumbers, dates and relative time (tn, td, tdr)
globalyesinstall: one instance for t! anywhere
serdenoa Text serializes as its translated string
watchnoreload changed files in debug builds
tauri-guestnoa Rust frontend inside Tauri, see Platforms

To build in only the number and date data of the locales you ship, set I18N_NEXT_LOCALES=en,de,ru at build time (Formats).

For a Tauri app add the plugin and allow it in a capability:

src-tauri/Cargo.toml
[dependencies]
i18n-next = "0.1"
tauri-plugin-i18n-next = "0.1"
src-tauri/capabilities/default.json
{
  "identifier": "default",
  "windows": ["main"],
  "permissions": ["core:default", "i18n-next:default"]
}

And the npm package with the @i18n-micro adapter you use:

pnpm add tauri-plugin-i18n-next-api @i18n-micro/vue
# or @i18n-micro/react, @i18n-micro/preact, @i18n-micro/solid, @i18n-micro/runtime

Rust

locales/
  en.json
  ru.json
  pages/settings/en.json
  pages/settings/ru.json
main.rs
use i18n_next::{I18n, t};

fn main() -> Result<(), i18n_next::Error> {
    I18n::builder()
        .config("i18n.json")          // optional: locales, defaultLocale, fallbackLocale
        .dir("locales")
        .locale("ru")
        .fallback("en")
        .install()?;                  // build + make it the global instance

    println!("{}", t!("nav.home"));
    println!("{}", t!("greeting", name = "Ann"));
    println!("{}", t!("title", @page = "settings"));
    i18n_next::set_locale("en")?;
    Ok(())
}

t! returns a lazy Text: it is resolved when shown, so a stored one follows set_locale. Without the global instance call methods on the instance: i18n.t("nav.home"). I18n is cheap to clone; share it between threads and tasks.

Tauri + Vue

src-tauri/src/lib.rs
macro_rules! file {                                 // a locale file, embedded in the binary
    ($path:literal) => { ($path, &include_bytes!(concat!("../../locales/", $path))[..]) };
}

let i18n = i18n_next::I18n::builder()
    .config_json(include_str!("../../i18n.json"))
    .files([file!("en.json"), file!("ru.json"), file!("pages/settings/en.json")])
    .missing(tauri_plugin_i18n_next::missing)       // dev report of missing keys
    .build()?;

tauri::Builder::default()
    .plugin(tauri_plugin_i18n_next::Builder::new(i18n).build())   // also installs it: t! works in Rust
    .run(tauri::generate_context!())?;

Embedded files work however the app is started. See Platforms for the other options.

src/main.ts
import { createApp } from 'vue'
import { createTauriI18n } from 'tauri-plugin-i18n-next-api/vue'

const app = createApp(App).use(router)
app.use(await createTauriI18n({ router }))
app.mount('#app')
Cart.vue
<i18n-t keypath="cart.total" :number="sum" />

The router guard loads each page's texts before the navigation finishes, so raw keys never flash. setLocale switches Rust and every window. More: Tauri.