From 935d331e971bc19019a4cbc271b3a59719b6be93 Mon Sep 17 00:00:00 2001 From: Requiem Date: Fri, 23 Aug 2019 11:02:24 +0200 Subject: [PATCH] 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. --- plume-front/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plume-front/src/main.rs b/plume-front/src/main.rs index a34e2ac..deb7884 100644 --- a/plume-front/src/main.rs +++ b/plume-front/src/main.rs @@ -46,10 +46,15 @@ lazy_static! { let catalogs = include_i18n!(); let lang = js! { return navigator.language }.into_string().unwrap(); let lang = lang.splitn(2, '-').next().unwrap_or("en"); + + let english_position = catalogs + .iter() + .position(|(language_code, _)| *language_code == "en") + .unwrap(); catalogs .iter() .find(|(l, _)| l == &lang) - .unwrap_or(&catalogs[0]) + .unwrap_or(&catalogs[english_position]) .clone() .1 };