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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # i18n
//!
//! You may add i18n (localization) support to your Freya app by using the [**dioxus-i18n**](https://github.com/dioxus-community/dioxus-i18n) crate.
//!
//! ```fluent
//! # en-US.ftl
//!
//! hello_world = Hello, World!
//! hello = Hello, {$name}!
//! ```
//!
//!
//! ```fluent
//! # es-ES.ftl
//!
//! hello_world = Hola, Mundo!
//! hello = Hola, {$name}!
//! ```
//!
//! ```rust
//! # use freya::prelude::*;
//! # use dioxus_i18n::{prelude::*, t};
//! # use dioxus_i18n::unic_langid::langid;
//!
//! // main.rs
//!
//! fn main() {
//!     # return;
//!     launch(app);
//! }
//!
//! #[allow(non_snake_case)]
//! fn Body() -> Element {
//!     // Access to the i18n state
//!     let mut i18n = i18n();
//!
//!     // Update the current language
//!     let change_to_english = move |_| i18n.set_language(langid!("en-US"));
//!     let change_to_spanish = move |_| i18n.set_language(langid!("es-ES"));
//!
//!     rsx!(
//!         rect {
//!             rect {
//!                 direction: "horizontal",
//!                 Button {
//!                     onpress: change_to_english,
//!                     label {
//!                         "English"
//!                     }
//!                 }
//!                 Button {
//!                     onpress: change_to_spanish,
//!                     label {
//!                         "Spanish"
//!                     }
//!                 }
//!             }
//!
//!             // Get and subscribe to these messages
//!             label { { t!("hello_world") } }
//!             label { { t!("hello", name: "Dioxus") } }
//!         }
//!     )
//! }
//!
//! fn app() -> Element {
//!     // Initialize our i18n config
//!     use_init_i18n(|| {
//!         # return I18nConfig::new(langid!("en-US"));
//!         I18nConfig::new(langid!("en-US"))
//!             .with_locale(Locale::new_static(
//!                 langid!("en-US"),
//!                 include_str!("./en-US.ftl"),
//!             ))
//!             .with_locale(Locale::new_dynamic(
//!                 langid!("es-ES"),
//!                 "./es-ES.ftl",
//!             ))
//!     });
//!
//!     rsx!(Body {})
//! }
//! ```