| Crates.io | tinyi18n-rs |
| lib.rs | tinyi18n-rs |
| version | 0.1.0 |
| created_at | 2026-01-11 18:46:36.087725+00 |
| updated_at | 2026-01-11 18:46:36.087725+00 |
| description | A tiny Rust i18n library that loads JSON language maps (modeled after vue-i18n) |
| homepage | |
| repository | https://github.com/knadh/tinyi18n-rs |
| max_upload_size | |
| id | 2036209 |
| size | 20,381 |
tinyi18n-rs is a tiny i18n library for Rust that loads {langKey: langValue} style JSON language maps. It is modeled after vue-i18n, enabling interoperability of the same language files in Rust backends and Vue frontends. It is a port of go-i18n.
A JSON language file is a simple map of key: value pairs. Singular/plural terms are represented as Singular|Plural. _.code and _.name are optional metadata fields. Check listmonk translations for complex examples.
{
"_.code": "en",
"_.name": "English",
"pageTitle": "Welcome to the page",
"page": "Single page|Many pages",
"greeting": "Hi {name}. Your age is {age}."
}
use tinyi18n_rs::I18n;
fn main() -> Result<(), tinyi18n_rs::Error> {
// If name and code args aren't passed, they're infered from _.code and _.name fields in JSON.
let i = I18n::from_file("en.json", None, None)?;
// Simple translation.
println!("{}", i.t("pageTitle")); // Welcome to the page
// Singular/plural.
println!("{}", i.t("page")); // Single page
println!("{}", i.s("page")); // Single page
println!("{}", i.p("page")); // Many pages
println!("{}", i.tc("page", 1)); // Single page
println!("{}", i.tc("page", 2)); // Many pages
// Parameter substitution with any type via .to_string().
println!("{}", i.ts("greeting", &[
("name", "Alice".into()),
("age", 30.to_string())
]));
// Hi Alice. Your age is 30.
Ok(())
}
Param values can reference other translation keys using the {key} syntax:
{
"app.name": "MyApp",
"welcome": "Welcome to {appName}"
}
i.ts("welcome", &[("appName", "{app.name}".into())]);
// Welcome to MyApp
Licensed under the MIT license.