Quick start
Install
[dependencies]
i18n-next = "0.1"
Rust 1.90 or newer, edition 2024. Features worth knowing (all of them: Features):
| Feature | Default | What |
|---|---|---|
format | yes | numbers, dates and relative time (tn, td, tdr) |
global | yes | install: one instance for t! anywhere |
serde | no | a Text serializes as its translated string |
watch | no | reload changed files in debug builds |
tauri-guest | no | a 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:
[dependencies]
i18n-next = "0.1"
tauri-plugin-i18n-next = "0.1"
{
"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
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
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.
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')
<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.