Fix issue #642, frontend not in english if the user language does not exist (#648)

* syntax and names

* Solve the issue #642, by searching index of english language code in catalog.
This commit is contained in:
Requiem 2019-08-23 11:02:24 +02:00 committed by Ana Gelez
parent 28fb50438e
commit 935d331e97
1 changed files with 6 additions and 1 deletions

View File

@ -46,10 +46,15 @@ lazy_static! {
let catalogs = include_i18n!(); let catalogs = include_i18n!();
let lang = js! { return navigator.language }.into_string().unwrap(); let lang = js! { return navigator.language }.into_string().unwrap();
let lang = lang.splitn(2, '-').next().unwrap_or("en"); let lang = lang.splitn(2, '-').next().unwrap_or("en");
let english_position = catalogs
.iter()
.position(|(language_code, _)| *language_code == "en")
.unwrap();
catalogs catalogs
.iter() .iter()
.find(|(l, _)| l == &lang) .find(|(l, _)| l == &lang)
.unwrap_or(&catalogs[0]) .unwrap_or(&catalogs[english_position])
.clone() .clone()
.1 .1
}; };