i18n-embed-fl
This crate provides a macro to perform compile time checks when using the i18n-embed crate and the fluent localization system.
See docs, and i18n-embed for more information.
Example
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):
# (Required) The language identifier of the language used in the
# source code for gettext system, and the primary fallback language
# (for which all strings must be present) when using the fluent
# system.
= "en-GB"
# Use the fluent localization system.
[]
# (Required) The path to the assets directory.
# The paths inside the assets directory should be structured like so:
# `assets_dir/{language}/{domain}.ftl`
= "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 -
):
hello-arg = Hello {$name}!
Simple set up of the FluentLanguageLoader
, and obtaining a message formatted with an argument:
use ;
use fl;
use RustEmbed;
;
let loader: FluentLanguageLoader = fluent_language_loader!;
loader
.load_languages
.unwrap;
assert_eq!
Convenience Macro
You will notice that this macro requires loader
to be specified in every call. For you project you may have access to a statically defined loader, and you can create a convenience macro wrapper so this doesn't need to be imported and specified every time.
This can now be invoked like so: fl!("message-id")
, fl!("message-id", args)
and fl!("message-id", arg = "value")
.