Expand description
§es-fluent-lang
Runtime support for es-fluent language management.
This crate provides the core language types (re-exporting unic-langid) and the optional “Language Enum” generator macro.
§Features
§#[es_fluent_language]
Generates a strongly-typed enum of all available languages in your project. It automatically scans your i18n.toml assets directory to find supported locales.
use es_fluent_lang::es_fluent_language;
use es_fluent::EsFluent;
use strum::EnumIter;
// Define an empty enum, and the macro fills it
#[es_fluent_language]
#[derive(Debug, Clone, Copy, PartialEq, Eq, EsFluent, EnumIter)]
pub enum Languages {}If your assets_dir contains en, fr, and de folders, this generates:
pub enum Languages {
En,
Fr,
De,
}It also implements:
Default: Uses thefallback_languagefrom your config.FromStr: Parses string codes (e.g., “en-US”) into the enum variant.TryFrom<&LanguageIdentifier>/TryFrom<LanguageIdentifier>: Converts from a locale ID and returns an error for unsupported locales.Into<LanguageIdentifier>: Converts back to a standard locale ID.
For user-facing labels, derive EsFluent on the generated enum and call
to_fluent_string() instead of relying on Display.
§Feature Flags
macros(default): Enables the#[es_fluent_language]macro.localized-langs: Use per-locale resources underi18n/<locale>/es-fluent-lang.ftlinstead of the embedded autonym file.bevy: Enables Bevy engine integration and force-link keepalive for module registration.
§Standard Translations
The crate also includes a built-in module for translating language names themselves (e.g., “English”, “Français”, “Deutsch”). This means you can easily build a “Language Picker” UI without manually translating the names of every language.
By default, language names are loaded from the embedded es-fluent-lang.ftl autonym file (language names in their native scripts). With the localized-langs feature, names are loaded from per-locale resources under i18n/<locale>/es-fluent-lang.ftl (generated by cargo run -p xtask -- generate-lang-names from ICU4X data; see xtask/README.md). The runtime resolves fallback locales when needed (for example, zh-CN will fall back to zh).
When the bevy feature is enabled, this crate uses the same standard module registration as other managers and provides a small force-link keepalive hook for Bevy/WASM builds.
Macros§
Structs§
- Language
Identifier LanguageIdentifieris a core struct representing a Unicode Language Identifier.
Attribute Macros§
- es_
fluent_ language - Attribute macro that expands a language enum based on the
i18n.tomlconfiguration. Which generates variants for each language in the i18n folder structure.