| Crates.io | tauri-plugin-i18n |
| lib.rs | tauri-plugin-i18n |
| version | 2.0.1 |
| created_at | 2025-11-02 16:51:30.61051+00 |
| updated_at | 2026-01-17 07:37:26.475925+00 |
| description | Internationalization plugin using rust_i18n for tauri apps. |
| homepage | |
| repository | https://github.com/razein97/tauri-plugin-i18n |
| max_upload_size | |
| id | 1913321 |
| size | 2,830,947 |
This plugin does not support macros from rust_i18n.
rust_i18n is only used for parsing the locales.

| Platform | Supported |
|---|---|
| Linux | ✓ |
| Windows | ✓ |
| macOS | ✓ |
| Android | Untested |
| iOS | Untested |
This plugin requires a Rust version of at least 1.77.2
Install the Core plugin by adding the following to your Cargo.toml file:
src-tauri/Cargo.toml
# Point this to your fork's repository and branch/tag/rev
# Example using a GitHub repo:
[dependencies.tauri-plugin-i18n]
git = "https://github.com/razein97/tauri-plugin-i18n"
# Or use a local path if developing locally:
# path = "../path/to/your/fork/tauri-plugin-i18n"
The package can also be installed by using cargo:
cargo add tauri-plugin-i18n
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
Install the JavaScript bindings using your preferred package manager:
# Using pnpm
pnpm add @razein97/tauri-plugin-i18n
# Using npm
npm install @razein97/tauri-plugin-i18n
# Using yarn
yarn add @razein97/tauri-plugin-i18n
You can use _version key to specify the version (This version is the locale file version, not the rust-i18n version) of the locale file, and the default value is 1.
rust-i18n supports two style of config file, and those versions will always be keeping.
_version: 1 - Split each locale into difference files, it is useful when your project wants to split to translate work._version: 2 - Put all localized text into same file, it is easy to translate quickly by AI (e.g.: GitHub Copilot). When you write original text, just press Enter key, then AI will suggest you the translation text for other languages.You can choose as you like.
_version: 1
You can also split the each language into difference files, and you can choose (YAML, JSON, TOML), for example: en.json:
.
├── Cargo.lock
├── Cargo.toml
├── locales
│ ├── zh-CN.yml
│ ├── en.yml
└── src
│ └── main.rs
_version: 1
hello: 'Hello world'
mello: 'Mello world'
Or use JSON or TOML format, just rename the file to en.json or en.toml, and the content is like this:
{
"_version": 1,
"hello": "Hello world",
"mello": "Mello world"
}
hello = "Hello world"
mello = "Mello world"
_version: 2
Make sure all localized files (containing the localized mappings) are located in the locales/ folder of the project root directory:
.
├── Cargo.lock
├── Cargo.toml
├── locales
│ ├── app.yml
│ ├── some-module.yml
└── src
│ └── main.rs
└── sub_app
│ └── locales
│ │ └── app.yml
│ └── src
│ │ └── main.rs
│ └── Cargo.toml
In the localized files, specify the localization keys and their corresponding values, for example, in app.yml:
_version: 2
hello:
en: Hello world
zh-CN: 你好世界
This is useful when you use GitHub Copilot, after you write a first translated text, then Copilot will auto generate other locale's translations for you.
First you need to register the core plugin with Tauri:
The init method takes two args:
src-tauri/src/lib.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_i18n::init(None))
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Afterwards all the plugin's APIs are available through the JavaScript guest bindings and also via tauri::AppHandle:
import I18n from '@razein97/tauri-plugin-i18n';
// Load translations
await I18n.getInstance().load();
// Example
//Get available locales
const locales = await I18n.getAvailableLocales();
console.log('Locales:', locales);
#[tauri::command]
fn get_locales(app: tauri::AppHandle)-> Vec<String> {
app.i18n().available_locales()
}
import I18n from '@razein97/tauri-plugin-i18n';
// Example
// Set the locale
await I18n.setLocale('en');
#[tauri::command]
fn update_locale(app: tauri::AppHandle, locale: &str) {
app.i18n().set_locale(locale);
}
Note: The i18n class must be instantiated in order to translate in javascript.
// In javascript, it uses the [data-i18n] attribute to remain framework agnostic
import I18n from '@razein97/tauri-plugin-i18n';
// Load translations
await I18n.getInstance().load();
// Example
// Use a translation
<p data-i18n="hello"> </p>;
let translated: Option<&str> = app.i18n().translate("hello");
Call the destroy method in javascript when done to cleanup.
See the examples folder for a working app.
Use package rust-i18n-autotranslate to autotranslate locales from a source locale.
Use .taurignore to prevent looping while running build.
This is because tauri tracks all files in the project unless explicitly ignored.
It can be used both at compile time and runtime
//build.rs
use rust_i18n_autotranslate::{
TranslationAPI,
config::{Config, TranslationProvider},
};
fn main() {
//run translations
let target_locales = [
"es", "zh-CN", "zh-TW", "hi", "ar", "fr", "pt-BR", "de", "ru", "ja", "ko", "it", "tr",
"id", "vi",
];
let cfg = Config::new()
.locales_directory("./locales")
.source_lang("en")
.add_target_langs(target_locales.to_vec())
.use_cache(true)
.translation_provider(TranslationProvider::DEEPL)
.build();
TranslationAPI::translate(cfg).unwrap();
tauri_build::build();
}