Expand description
§dioxus-rust-i18n
Dioxus integration for rust-i18n.
§Installation
cargo add dioxus-rust-i18n rust-i18n§Quick Start
ⓘ
use dioxus::prelude::*;
use dioxus_rust_i18n::{i18n, t};
i18n!("locales", fallback = ["en"]);
#[component]
fn App() -> Element {
let mut i18n = use_init_i18n();
rsx! {
button {
onclick: move |_| i18n.set_language("zh-CN"),
"Switch language"
}
p { { t!("welcome") } }
p { { t!("hello_user", name = "Dioxus") } }
}
}§Documentation
See docs.rs for full API documentation.
§Crates
| Crate | Description |
|---|---|
dioxus-rust-i18n | Main crate for Dioxus apps |
dioxus-rust-i18n-macro | Procedural macros used by the main crate |
§License
Macros§
- i18n
- Wraps the [
rust_i18n::i18n!] macro and additionally generates Dioxus bridge helpers. - t
- Translates a key inside a Dioxus render context, panicking on failure.
- te
- Tries to translate a key inside a Dioxus render context.
- tid
- Translates a key inside a Dioxus render context and falls back to the key itself on failure.
Structs§
- I18n
Runtime - Immutable translation runtime used by both manual integrations and Dioxus sessions.
- I18n
Session - Reactive Dioxus handle for reading and switching the current language.
Enums§
- I18n
Error - Errors produced by low-level translation APIs.
Functions§
- global_
locale - Returns the explicit non-reactive global locale mirror.
- set_
global_ locale - Sets the explicit non-reactive global locale mirror.
- translate_
global - Translates a key using the registered global runtime, panicking on failure.
- translate_
global_ with_ args - Translates a key with interpolation arguments using the global runtime, panicking on failure.
- try_
translate_ global - Tries to translate a key using the registered global runtime.
- try_
translate_ global_ with_ args - Tries to translate a key with interpolation arguments using the global runtime.
- use_
i18n - Retrieves the current Dioxus i18n session from context.
- use_
init_ i18n_ from - Initializes a Dioxus i18n session from a fully constructed runtime.