Some checks failed
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 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 11s
hadolint check / hadolint check (pull_request) Successful in 14s
Prettier check / Prettier check (pull_request) Failing after 35s
markdownlint check / markdownlint check (pull_request) Failing after 40s
htmlhint check / htmlhint check (pull_request) Successful in 44s
checkov check / checkov check (pull_request) Failing after 1m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 23s
Stylelint check / Stylelint check (pull_request) Successful in 24s
yamllint check / yamllint check (pull_request) Successful in 22s
Rust check / Rust check (pull_request) Failing after 57m45s
86 lines
2.3 KiB
Markdown
86 lines
2.3 KiB
Markdown
# dioxus-i18n 🌍
|
|
|
|
i18n integration for Dioxus apps based on the [Project Fluent](https://github.com/projectfluent/fluent-rs).
|
|
|
|
> This crate used to be in the [Dioxus SDK](https://github.com/DioxusLabs/sdk).
|
|
|
|
## Support
|
|
|
|
- **Dioxus v0.6** 🧬
|
|
- Renderers:
|
|
- [web](https://dioxuslabs.com/learn/0.6/guides/web/),
|
|
- [desktop](https://dioxuslabs.com/learn/0.6/guides/desktop/),
|
|
- [freya](https://github.com/marc2332/freya)
|
|
- Both WASM and native targets
|
|
|
|
## Example:
|
|
|
|
```ftl
|
|
# en-US.ftl
|
|
|
|
hello = Hello, {$name}!
|
|
```
|
|
|
|
```rs
|
|
// main.rs
|
|
|
|
fn app() -> Element {
|
|
let i18 = use_init_i18n(|| {
|
|
I18nConfig::new(langid!("en-US"))
|
|
// implicit [`Locale`]
|
|
.with_locale(( // Embed
|
|
langid!("en-US"),
|
|
include_str!("./en-US.ftl")
|
|
))
|
|
.with_locale(( // Load at launch
|
|
langid!("es-ES"),
|
|
PathBuf::from("./es-ES.ftl"),
|
|
))
|
|
.with_locale(( // Locales will share duplicated locale_resources
|
|
langid!("en"), // which is useful to assign a specific region for
|
|
include_str!("./en-US.ftl") // the primary language
|
|
))
|
|
// explicit [`Locale`]
|
|
.with_locale(Locale::new_static( // Embed
|
|
langid!("en-US"),
|
|
include_str!("./en-US.ftl"),
|
|
))
|
|
.with_locale(Locale::new_dynamic( // Load at launch
|
|
langid!("es-ES"),
|
|
PathBuf::from("./es-ES.ftl"),
|
|
))
|
|
});
|
|
|
|
rsx!(
|
|
label { { t!("hello", name: "World") } }
|
|
)
|
|
}
|
|
```
|
|
|
|
## Further examples
|
|
|
|
The examples folder contains a number of working examples:
|
|
|
|
* Desktop examples:
|
|
* [Dioxus](./examples/dioxus-desktop.rs)
|
|
* [Freya](./examples/freya.rs)
|
|
* Configuration variants:
|
|
* [Auto locales](./examples/config-auto-locales.rs)
|
|
* [Dynamic (PathBuf)](./examples/config-dynamic-pathbuf.rs)
|
|
* [Static (include_str!)](./examples/config-static-includestr.rs)
|
|
* Fluent grammer:
|
|
* [Application](./examples/fluent-grammar.rs)
|
|
* [FTL file](./examples/data/fluent/en.ftl)
|
|
|
|
## Development
|
|
|
|
```bash
|
|
# Checks clean compile against `#[cfg(not(target_arch = "wasm32"))]`
|
|
cargo build --target wasm32-unknown-unknown
|
|
|
|
# Runs all tests
|
|
cargo test
|
|
```
|
|
|
|
[MIT License](./LICENSE.md)
|