Some checks failed
hadolint check / hadolint check (pull_request) Successful in 13s
actionlint check / actionlint check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 3s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 6s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 7s
GitLeaks check / GitLeaks check (pull_request) Successful in 13s
markdownlint check / markdownlint check (pull_request) Failing after 54s
Prettier check / Prettier check (pull_request) Failing after 51s
htmlhint check / htmlhint check (pull_request) Successful in 1m3s
checkov check / checkov check (pull_request) Failing after 2m26s
ShellCheck check / ShellCheck check (pull_request) Successful in 1m14s
Stylelint check / Stylelint check (pull_request) Successful in 1m27s
Rust check / Rust check (pull_request) Failing after 11m40s
yamllint check / yamllint check (pull_request) Successful in 13m36s
48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
//! This example demonstrates how to use an auto_locales derived I18nConfig.
|
|
//! This is useful when you have a lot of locales and you don't want to manually add them.
|
|
|
|
use dioxus::prelude::*;
|
|
use dioxus_i18n::{prelude::*, t};
|
|
use unic_langid::langid;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
launch(app);
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
fn Body() -> Element {
|
|
let mut i18n = i18n();
|
|
|
|
let change_to_english = move |_| i18n.set_language(langid!("en-US"));
|
|
let change_to_spanish = move |_| i18n.set_language(langid!("es-ES"));
|
|
|
|
rsx!(
|
|
button {
|
|
onclick: change_to_english,
|
|
label {
|
|
"English"
|
|
}
|
|
}
|
|
button {
|
|
onclick: change_to_spanish,
|
|
label {
|
|
"Spanish"
|
|
}
|
|
}
|
|
p { { t!("hello_world") } }
|
|
p { { t!("hello", name: "Dioxus") } }
|
|
)
|
|
}
|
|
|
|
fn app() -> Element {
|
|
use_init_i18n(|| {
|
|
// This initialisation performs a deep search for all locales in the given path.
|
|
// It IS NOT supported in WASM targets.
|
|
I18nConfig::new(langid!("en-US")).with_auto_locales(PathBuf::from("./examples/data/i18n/"))
|
|
});
|
|
|
|
rsx!(Body {})
|
|
}
|