1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-09 04:22:45 +03:00

i18n: make the message translator fallback to en

This commit is contained in:
Quentin Gliech
2024-02-01 18:07:03 +01:00
parent 36ebbc4d70
commit 3df600b5d7

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();