Expand description
§dioxus-i18n 🌍
i18n integration for Dioxus apps based on the Project Fluent.
This crate used to be in the Dioxus SDK.
§Support
§Example:
# en-US.ftl
hello = Hello, {$name}!// main.rs
fn app() -> Element {
let i18 = use_init_i18n(|| {
I18nConfig::new(langid!("en-US"))
// implicit [`Locale`]
.with_locale(( // Embed
langid!("en-US"),
include_str!("./en-US.ftl")
))
.with_locale(( // Load at launch
langid!("es-ES"),
PathBuf::from("./es-ES.ftl"),
))
.with_locale(( // Locales will share duplicated locale_resources
langid!("en"), // which is useful to assign a specific region for
include_str!("./en-US.ftl") // the primary language
))
// explicit [`Locale`]
.with_locale(Locale::new_static( // Embed
langid!("en-US"),
include_str!("./en-US.ftl"),
))
.with_locale(Locale::new_dynamic( // Load at launch
langid!("es-ES"),
PathBuf::from("./es-ES.ftl"),
))
});
rsx!(
label { { t!("hello", name: "World") } }
)
}§Further examples
The examples folder contains a number of working examples:
- Desktop examples:
- Configuration variants:
- Fluent grammer:
§Development
# Checks clean compile against `#[cfg(not(target_arch = "wasm32"))]`
cargo build --target wasm32-unknown-unknown
# Runs all tests
cargo testRe-exports§
pub use fluent;pub use unic_langid;
Modules§
- i18n_
macro - Key translation macros.
- prelude
- use_
i18n
Macros§
- t
- Translate message from key, panic! if id not found…
- te
- Translate message from key, returning
crate::prelude::DioxusI18nErrorif id not found… - tid
- Translate message from key, return id if no translation found…