freya_i18n/
lib.rs

1//! # i18n
2//!
3//! You may add i18n (localization) support to your Freya app by using the [**freya-i18n**](https://crates.io/crates/freya-i18n) crate.
4//! You can also enable its reexport by turning on the `i18n` feature in `freya`.
5//!
6//! ```fluent
7//! # en-US.ftl
8//!
9//! hello_world = Hello, World!
10//! hello = Hello, {$name}!
11//! ```
12//!
13//!
14//! ```fluent
15//! # es-ES.ftl
16//!
17//! hello_world = Hola, Mundo!
18//! hello = Hola, {$name}!
19//! ```
20//!
21//! ```rust
22//! # use freya::prelude::*;
23//! # use freya_i18n::prelude::*;
24//! // main.rs
25//! #[derive(PartialEq)]
26//! struct Body;
27//!
28//! impl Component for Body {
29//!     fn render(&self) -> impl IntoElement {
30//!         // Access to the i18n state
31//!         let mut i18n = I18n::get();
32//!
33//!         // Update the current language
34//!         let change_to_english = move |_| i18n.set_language(langid!("en-US"));
35//!         let change_to_spanish = move |_| i18n.set_language(langid!("es-ES"));
36//!
37//!         rect()
38//!           .expanded()
39//!           .center()
40//!           .child(
41//!               rect()
42//!                   .horizontal()
43//!                   .child(Button::new().on_press(change_to_english).child("English"))
44//!                   .child(Button::new().on_press(change_to_spanish).child("Spanish")),
45//!           )
46//!          .child(t!("hello_world"))
47//!          .child(t!("hello", name: "Freya!"))
48//!     }
49//! }
50//!
51//! fn app() -> impl IntoElement {
52//!     // Initialize our i18n config
53//!     use_init_i18n(|| {
54//!         I18nConfig::new(langid!("en-US"))
55//!             .with_locale(Locale::new_static(
56//!                 langid!("en-US"),
57//!                 include_str!("../../../examples/i18n/en-US.ftl"),
58//!             ))
59//!             .with_locale(Locale::new_dynamic(
60//!                 langid!("es-ES"),
61//!                 "../../../examples/i18n/es-ES.ftl",
62//!             ))
63//!     });
64//!
65//!     Body
66//! }
67//! ```
68
69mod error;
70pub mod i18n;
71pub mod i18n_macro;
72
73pub use fluent;
74pub use unic_langid;
75
76pub mod prelude {
77    pub use unic_langid::{
78        LanguageIdentifier,
79        lang,
80        langid,
81    };
82
83    pub use crate::{
84        error::Error as DioxusI18nError,
85        i18n::*,
86        t,
87        te,
88        tid,
89    };
90}