Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 3df600b

Browse files
committed
i18n: make the message translator fallback to en
1 parent 36ebbc4 commit 3df600b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/i18n/src/translator.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct Translator {
5050
plural_provider: LocaleFallbackProvider<icu_plurals::provider::Baked>,
5151
list_provider: LocaleFallbackProvider<icu_list::provider::Baked>,
5252
fallbacker: LocaleFallbacker,
53+
default_locale: DataLocale,
5354
}
5455

5556
impl Translator {
@@ -71,6 +72,8 @@ impl Translator {
7172
plural_provider,
7273
list_provider,
7374
fallbacker,
75+
// TODO: make this configurable
76+
default_locale: icu_locid::locale!("en").into(),
7477
}
7578
}
7679

@@ -135,9 +138,10 @@ impl Translator {
135138
return Some((message, iter.take()));
136139
}
137140

138-
// Stop if we hit the `und` locale
141+
// Try the defaut locale if we hit the `und` locale
139142
if locale.is_und() {
140-
return None;
143+
let message = self.message(&self.default_locale, key).ok()?;
144+
return Some((message, self.default_locale.clone()));
141145
}
142146

143147
iter.step();

0 commit comments

Comments
 (0)