-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig-auto-locales.rs
47 lines (39 loc) · 1.17 KB
/
config-auto-locales.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! 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 {})
}