Internationalization and localization

Version 0.2.0 Updated Dec 08, 2025

Writing feature files in other languages

Feature files can opt into any Gherkin localization. Add a # language: <code> directive on the first line of the .feature file and keep the remainder of the scenario in the target language:

# language: es
Característica: Control de stock
  Escenario: Añadir una calabaza
    Dado un inventario vacío
    Cuando registro una calabaza
    Entonces el inventario contiene una calabaza

The scenario parser reads the declaration and hands keyword matching to the gherkin crate, so existing #[given], #[when], and #[then] definitions continue to match without code changes. Omitting the directive keeps the default English vocabulary to preserve backwards compatibility.

Localizing runtime diagnostics

rstest-bdd now ships its user-facing diagnostics via Fluent translation files. The crate bundles English strings by default and falls back to them when no translation is available. Applications can opt into additional locales by embedding the provided assets and selecting a language at runtime.

Localization tooling can be added to Cargo.toml as follows:

[dependencies]
rstest-bdd = "0.1.0"
i18n-embed = { version = "0.16", features = ["fluent-system", "desktop-requester"] }
unic-langid = "0.9"

The crate exposes the embedded assets via the [Localizations] helper. This type implements i18n_embed::I18nAssets, allowing applications with existing Fluent infrastructure to load resources into their own [FluentLanguageLoader]. Libraries without a localization framework can rely on the built-in loader and request a different language at runtime:

# fn scope_locale() -> Result<(), rstest_bdd::localization::LocalizationError> {
use rstest_bdd::select_localizations;
use unic_langid::langid;

select_localizations(&[langid!("fr")])?; // Switch diagnostics to French
# Ok(())
# }

The selection function preserves the caller-supplied order, so applications can pass a list of preferred locales. The helper resolves to the best available translation and continues to fall back to English when a requested locale is not shipped with the crate. Procedural macro diagnostics remain in English so compile-time output stays deterministic regardless of the host machine’s language settings.