Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

Localization for Rust backend

Petteri Kautonen edited this page Jul 17, 2024 · 3 revisions

Localization for Rust backend

To have the Rust backend of the Tauri application to use the same localization data, transform the i18next localization files by installing the crate rust-i18n:

cargo add rust-i18n

Transform the localization to different format

To transform the localization from [PATH]/src/localization into the [PATH]/src-tauri/locales for the backend to use, run in the [PATH]/src/localization/rust_i18n_transform folder:

npm run buildRun

Use the localizations in the backend

  1. Insert the following code to the lib.rs file:
#[macro_use]
extern crate rust_i18n;
i18n!();   
  1. Use the macro in the respective file
use rust_i18n::t;
  1. Sample usage
fn my_error(file_name: &str) -> String {
    let msg = t!("messages.updateCheckFailedFile", error = file_name).into_owned();
    msg
}

See also

Clone this wiki locally