10 unstable releases (3 breaking)

new 0.4.3 Mar 16, 2025
0.4.2 Feb 7, 2025
0.3.0 Dec 10, 2024
0.2.5 Sep 10, 2024
0.1.0 Aug 31, 2024

#47 in Accessibility

Download history 30/week @ 2024-11-26 7/week @ 2024-12-03 294/week @ 2024-12-10 125/week @ 2024-12-17 79/week @ 2024-12-24 71/week @ 2024-12-31 73/week @ 2025-01-07 122/week @ 2025-01-14 69/week @ 2025-01-21 192/week @ 2025-01-28 436/week @ 2025-02-04 131/week @ 2025-02-11 131/week @ 2025-02-18 83/week @ 2025-02-25 120/week @ 2025-03-04 231/week @ 2025-03-11

581 downloads per month

MIT license

70KB
619 lines

dioxus-i18n 🌍

i18n integration for Dioxus apps based on the Project Fluent.

This crate used to be in the Dioxus SDK.

Support

  • Dioxus v0.6 🧬
  • Renderers:
  • Both WASM and native targets

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:

Development

# Checks clean compile against `#[cfg(not(target_arch = "wasm32"))]`
cargo build --target wasm32-unknown-unknown

# Runs all tests
cargo test

MIT License

Dependencies

~5–12MB
~139K SLoC