Skip to main content

Crate dioxus_rust_i18n

Crate dioxus_rust_i18n 

Source
Expand description

§dioxus-rust-i18n

Crates.io Version docs.rs

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

CrateDescription
dioxus-rust-i18nMain crate for Dioxus apps
dioxus-rust-i18n-macroProcedural macros used by the main crate

§License

MIT. Made with ❤️ by Ray

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§

I18nRuntime
Immutable translation runtime used by both manual integrations and Dioxus sessions.
I18nSession
Reactive Dioxus handle for reading and switching the current language.

Enums§

I18nError
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.