#localization #freya

freya-i18n

i18n integration for Freya Apps based on Fluent Project

26 releases

Uses new Rust 2024

0.4.0-rc.19 Apr 23, 2026
0.4.0-rc.18 Apr 11, 2026
0.4.0-rc.16 Mar 26, 2026
0.4.0-rc.10 Feb 24, 2026
0.4.0-alpha.8 Dec 30, 2025

#64 in Accessibility

MIT license

495KB
12K SLoC

i18n

You may add i18n (localization) support to your Freya app by using the freya-i18n crate. You can also enable its reexport by turning on the i18n feature in freya.


hello_world = Hello, World!
hello = Hello, {$name}!

hello_world = Hola, Mundo!
hello = Hola, {$name}!
// main.rs
#[derive(PartialEq)]
struct Body;

impl Component for Body {
    fn render(&self) -> impl IntoElement {
        // Access to the i18n state
        let mut i18n = I18n::get();

        // Update the current language
        let change_to_english = move |_| i18n.set_language(langid!("en-US"));
        let change_to_spanish = move |_| i18n.set_language(langid!("es-ES"));

        rect()
          .expanded()
          .center()
          .child(
              rect()
                  .horizontal()
                  .child(Button::new().on_press(change_to_english).child("English"))
                  .child(Button::new().on_press(change_to_spanish).child("Spanish")),
          )
         .child(t!("hello_world"))
         .child(t!("hello", name: "Freya!"))
    }
}

fn app() -> impl IntoElement {
    // Initialize our i18n config
    use_init_i18n(|| {
        I18nConfig::new(langid!("en-US"))
            .with_locale(Locale::new_static(
                langid!("en-US"),
                include_str!("../../../examples/i18n/en-US.ftl"),
            ))
            .with_locale(Locale::new_dynamic(
                langid!("es-ES"),
                "../../../examples/i18n/es-ES.ftl",
            ))
    });

    Body
}

Dependencies

~10–15MB
~217K SLoC