This crate provides a macro to perform compile time checks when using the i18n-embed crate and the fluent localization system.
Set up a minimal i18n.toml
in your crate root to use with cargo-i18n
(see cargo i18n for more information on the configuration file format):
```toml
fallback_language = "en-GB"
[fluent]
assets_dir/{language}/{domain}.ftl
assets_dir = "i18n" ```
Create a fluent localization file for the en-GB
language in i18n/en-GB/{domain}.ftl
, where domain
is the rust path of your crate (_
instead of -
):
fluent
hello-arg = Hello {$name}!
Simple set up of the FluentLanguageLoader
, and obtaining a message formatted with an argument:
```rust use i18nembed::{ fluent::{fluentlanguageloader, FluentLanguageLoader}, LanguageLoader, }; use i18nembedfl::fl; use rustembed::RustEmbed;
struct Localizations;
let loader: FluentLanguageLoader = fluentlanguageloader!(); loader .loadlanguages(&Localizations, &[loader.fallbacklanguage()]) .unwrap();
assert_eq!(
"Hello \u{2068}Bob 23\u{2069}!",
// Compile time check for message id, and the name
argument,
// to ensure it matches what is specified in the fallback_language
's
// fluent resource file.
fl!(loader, "hello-arg", name = format!("Bob {}", 23))
)
```
See docs, and i18n-embed for more information.