Fix issue #642, frontend not in english if the user language does not exist #648
1 changed files with 6 additions and 1 deletions
|
@ -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
|
||||||
![]() It should be a constant yes, but the rust doc of constant says :
So i thought the keyword const was forbidden in this case. It should be a constant yes, but the rust doc of constant says :
> Constants can be set only to a constant expression and not to the result of a function call or any other value that will be computed at runtime.
So i thought the keyword const was forbidden in this case.
trinity-1686a
commented
All this is in a lazy_static! call, so the result will be evaluated only one time, the first time CATALOG is accessed. The only thing it's not is cached between two different page loading, but that's not necessary imo All this is in a lazy_static! call, so the result will be evaluated only one time, the first time CATALOG is accessed. The only thing it's not is cached between two different page loading, but that's not necessary imo
|
|||||||
|
.iter()
|
||||||
|
.position(|(language_code, _)| *language_code == "en")
|
||||||
|
.unwrap();
|
||||||
![]() while i understand that this is a simple operation, i don't think we need to do it every time while i understand that this is a simple operation, i don't think we need to do it every time
![]() actually, never mind, this is an operation that's only dealing with things known at compile time the optimiser will probably inline this as a constant literal actually, never mind, this is an operation that's only dealing with things known at compile time
the optimiser will probably inline this as a constant literal
|
|||||||
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
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue
this should be either a (cached?) constant, or a (cached?) config value