es-fluent-lang
This crate provides the #[es_fluent_language] procedural macro for automatically generating a language selection enum based on your project's localization setup.
Features
- Automatic Enum Generation: Reads your
i18n.tomlfile to discover available languages and generates a Rustenumwith a variant for each one. - Compile-Time Validation: Ensures that all languages defined in your localization assets are valid and supported by the
es-fluent-langdata crate. - Convenient Conversions: Implements
Fromconversions to and fromunic_langid::LanguageIdentifierfor seamless integration with Fluent. - Default Fallback: Automatically implements
Defaultfor the enum, using thefallback_languagespecified in youri18n.toml.
Usage
First, add the crate to your Cargo.toml:
[]
= "*"
= "*"
Then, define your language enum in your code:
use EsFluent;
use es_fluent_language;
use LanguageIdentifier;
use EnumIter;
// Now you can use the generated enum:
The macro will expand the empty Language enum into one with variants corresponding to the languages found in the directory specified by assets_dir in your i18n.toml. For example, if you have en and fr directories, the enum will have En and Fr variants.