-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from alexanderjophus/master
Updates i18n page to embed example
- Loading branch information
Showing
5 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
This section of the guide provides getting started guides for common tools used with Dioxus. | ||
|
||
- [Logging](./logging.md) | ||
- [Internationalization](./internationalization.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use dioxus::prelude::*; | ||
use dioxus_std::i18n::*; | ||
use dioxus_std::translate; | ||
use std::str::FromStr; | ||
|
||
fn main() { | ||
dioxus_web::launch(app); | ||
} | ||
|
||
static EN_US: &str = r#"{ | ||
"id": "en-US", | ||
"texts": { | ||
"messages": { | ||
"hello_world": "Hello World!" | ||
}, | ||
"messages.hello": "Hello {name}" | ||
} | ||
}"#; | ||
static ES_ES: &str = r#"{ | ||
"id": "es-ES", | ||
"texts": { | ||
"messages": { | ||
"hello_world": "Hola Mundo!" | ||
}, | ||
"messages.hello": "Hola {name}" | ||
} | ||
}"#; | ||
|
||
#[allow(non_snake_case)] | ||
fn Body(cx: Scope) -> Element { | ||
let i18 = use_i18(cx); | ||
|
||
let change_to_english = move |_| i18.set_language("en-US".parse().unwrap()); | ||
let change_to_spanish = move |_| i18.set_language("es-ES".parse().unwrap()); | ||
|
||
render!( | ||
button { | ||
onclick: change_to_english, | ||
label { | ||
"English" | ||
} | ||
} | ||
button { | ||
onclick: change_to_spanish, | ||
label { | ||
"Spanish" | ||
} | ||
} | ||
p { translate!(i18, "messages.hello_world") } | ||
p { translate!(i18, "messages.hello", name: "Dioxus") } | ||
) | ||
} | ||
|
||
fn app(cx: Scope) -> Element { | ||
use_init_i18n( | ||
cx, | ||
"en-US".parse().unwrap(), | ||
"en-US".parse().unwrap(), | ||
|| { | ||
let en_us = Language::from_str(EN_US).unwrap(); | ||
let es_es = Language::from_str(ES_ES).unwrap(); | ||
vec![en_us, es_es] | ||
}, | ||
); | ||
|
||
render!(Body {}) | ||
} |