Skip to content

i18n (localization) support for all Dioxus apps and renderers

License

Notifications You must be signed in to change notification settings

nigeleke/dioxus-i18n

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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") } }
    )
}

Development

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

# Runs all tests
cargo test

MIT License

About

i18n (localization) support for all Dioxus apps and renderers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 98.3%
  • Fluent 1.7%