Skip to main content

Crate frus_l10n

Crate frus_l10n 

Source
Expand description

frus-l10n — localisation for frus applications, built on Fluent, Mozilla’s i18n standard.

Nothing is reinvented here: messages, plurals and selections live in .ftl resources, embedded by the application through include_str!, and resolved per locale with a fallback chain (fluent-langneg negotiation).

use frus_l10n::{Localizer, args};
let mut l10n = Localizer::new("en");
l10n.add("en", "hello = Hello, { $name }!\ntasks = { $n ->\n    [one] { $n } task\n   *[other] { $n } tasks\n }");
l10n.add("fr", "hello = Bonjour, { $name } !\ntasks = { $n ->\n    [one] { $n } tâche\n   *[other] { $n } tâches\n }");

assert_eq!(l10n.format("hello", args![name: "Ada"]), "Hello, Ada!");
l10n.set_locale("fr");
assert_eq!(l10n.format("tasks", args![n: 2]), "2 tâches");
// Falls back to the default locale when the key is missing from the current one.

Macros§

args
Builds a message’s argument list: args![name: "Ada", n: 3].

Structs§

Localizer
The localiser: Fluent bundles per locale, a current locale and a default locale, the latter being the last resort.

Enums§

Arg
An argument value passed to a message: a string or a number.