Skip to content

Commit

Permalink
perf(i18n): ⚡️ removed needless translations fetch if not using i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Sep 18, 2021
1 parent 8bf6dd5 commit 7c6f697
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/perseus/src/client_translations_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl ClientTranslationsManager {
{
Ok(Rc::clone(self.cached_translator.as_ref().unwrap()))
} else {
// Check if the locale is supported
if self.locales.is_supported(locale) {
// Check if the locale is supported and we're actually using i18n
if self.locales.is_supported(locale) && self.locales.using_i18n {
// Get the translations data
let asset_url = format!("/.perseus/translations/{}", locale);
// If this doesn't exist, then it's a 404 (we went here by explicit navigation after checking the locale, so that's a bug)
Expand Down Expand Up @@ -68,6 +68,13 @@ impl ClientTranslationsManager {
self.cached_translator = Some(Rc::new(translator));
// Now return that
Ok(Rc::clone(self.cached_translator.as_ref().unwrap()))
} else if !self.locales.using_i18n {
// If we aren't even using i18n, then it would be pointless to fetch translations
let translator = Translator::new("xx-XX".to_string(), "".to_string()).unwrap();
// Cache that translator
self.cached_translator = Some(Rc::new(translator));
// Now return that
Ok(Rc::clone(self.cached_translator.as_ref().unwrap()))
} else {
bail!(ErrorKind::LocaleNotSupported(locale.to_string()))
}
Expand Down

0 comments on commit 7c6f697

Please sign in to comment.