i18n: make the message translator fallback to en

This commit is contained in:
Quentin Gliech committed 2024-02-02 18:01:51 +01:00
1 parent 36ebbc4d70
commit 3df600b5d7
1 file changed
+6 -2
+6 -2
View File
@@ -50,6 +50,7 @@ pub struct Translator {
plural_provider: LocaleFallbackProvider<icu_plurals::provider::Baked>,
list_provider: LocaleFallbackProvider<icu_list::provider::Baked>,
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();