From 3df600b5d7773487f1d585ebaba61fa0c1484fea Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 1 Feb 2024 18:07:03 +0100 Subject: [PATCH] i18n: make the message translator fallback to `en` --- crates/i18n/src/translator.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/i18n/src/translator.rs b/crates/i18n/src/translator.rs index 5523a9ad..4d437ebd 100644 --- a/crates/i18n/src/translator.rs +++ b/crates/i18n/src/translator.rs @@ -50,6 +50,7 @@ pub struct Translator { plural_provider: LocaleFallbackProvider, list_provider: LocaleFallbackProvider, fallbacker: LocaleFallbacker, + default_locale: DataLocale, } impl Translator { @@ -71,6 +72,8 @@ impl Translator { plural_provider, list_provider, fallbacker, + // TODO: make this configurable + default_locale: icu_locid::locale!("en").into(), } } @@ -135,9 +138,10 @@ impl Translator { return Some((message, iter.take())); } - // Stop if we hit the `und` locale + // Try the defaut locale if we hit the `und` locale if locale.is_und() { - return None; + let message = self.message(&self.default_locale, key).ok()?; + return Some((message, self.default_locale.clone())); } iter.step();