i18n
Locales, catalogs, optional path prefix and cookie · crate sova-i18n 0.1.0 · id i18n
bash
cargo add sova --features i18n,i18n-cookie| Feature | What you get |
|---|---|
i18n | Locales and catalogs (sova-i18n). |
i18n-cookie | Remember locale in a cookie. |
Two-level i18n for Sova (root + page scopes).
Usage
Add locales on the web preset (templates already available):
rust
use sova::prelude::*;
use sova::{I18n, Locale, Parser, ServerArgs};
#[tokio::main]
async fn main() -> Result<()> {
let args = ServerArgs::parse();
args.init_tracing();
let mut app = App::web()
.site("App")
.public_url("https://example.com")
.into_app();
app.install(
I18n::new(
"locales",
vec![
Locale::new("en").with_name("English"),
Locale::new("ru").with_name("Русский"),
],
)
.fallback("en")
.cookie("locale")
.set_locale_cookie(true),
);
app.run().await
}In MiniJinja: wire per_request("t", sova::template_fn). Demos: i18n, templates_i18n.
