es-fluent-lang

Crates.ioes-fluent-lang
lib.rses-fluent-lang
version0.6.0
created_at2025-10-20 12:08:11.187993+00
updated_at2026-01-16 12:03:48.69534+00
descriptionOpinionated crate for adding variants to a Language Enum.
homepage
repositoryhttps://github.com/stayhydated/es-fluent
max_upload_size
id1891824
size40,485
stayhydated (stayhydated)

documentation

README

Docs Crates.io

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 the fallback_language from your config.
  • FromStr: Parses string codes (e.g., "en-US") into the enum variant.
  • Into<LanguageIdentifier>: Converts back to a standard locale ID.

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.

Commit count: 444

cargo fmt