i18n-rs
i18n-rs is a lightweight internationalization helper designed to be embedded in any Rust web framework. It focuses on a familiar JSON-based translation file so you can reuse the dictionaries you already maintain while keeping your web stack framework agnostic.
Features
- Loads translations from JSON files, strings, or any reader.
- Automatically flattens nested translation keys using dot notation.
- Optional fallback language for missing translations.
- Straightforward API that suits synchronous and async contexts alike.
Installation
Add the crate to your project:
[]
= "1.0.0"
Translator File Format
The crate expects a JSON object whose top-level keys are language identifiers. Each language contains nested objects and/or string values. Nested keys are automatically flattened using dot notation.
The example above yields the keys greeting.welcome and greeting.farewell.
Usage
use Translator;
static JSON: &str = r#"{
"en": {
"welcome": "Welcome!",
"farewell": "See you later!",
"button": {
"submit": "Submit"
}
},
"es": {
"welcome": "¡Bienvenido!",
"button": {
"submit": "Enviar"
}
}
}"#;