Fix language match on Linux (Unix?)#104
Conversation
2e04511 to
0e843c9
Compare
|
I don't think this is correct. E.g. pub fn preferred_languages(arena: &Arena) -> Vec<ArenaString<'_>, &Arena> {
let mut locales = Vec::new_in(arena);
for key in ["LANGUAGE", "LC_ALL", "LANG"] {
if let Ok(langs) = std::env::var(key) {
let langs = langs
// split colon separated entries
.split(':')
// strip territory ("EN" in "en_EN")
.map(|s| s.split('_').next().unwrap_or(s))
// strip codeset ("utf8" in "C.utf8")
.map(|s| s.split('.').next().unwrap_or(s))
// filter out empty entries
.filter(|s| !s.is_empty())
// intern strings in arena
.map(|s| ArenaString::from_str(arena, s));
locales.extend(langs);
if !locales.is_empty() {
break;
}
}
}
locales
} |
0e843c9 to
e35b620
Compare
|
@microsoft-github-policy-service agree |
e35b620 to
9f323ce
Compare
|
@eatradish, oops, I just noticed that the territory must not be stripped: edit/src/bin/edit/localization.rs Lines 934 to 937 in e8d40f6 Could you replace the stripping of everything after |
I agree, but I think it's equally important to add the value you get from the |
|
Sorry, I did not express myself properly (by using the word "replace" twice):
|
I changed it to this, but for the final result I still have to split the '-' to successfully match 'zh': pub fn preferred_languages(arena: &Arena) -> Vec<ArenaString<'_>, &Arena> {
let mut locales = Vec::new_in(arena);
for key in ["LANGUAGE", "LC_ALL", "LANG"] {
if let Ok(langs) = std::env::var(key) {
let langs = langs.replace('_', "-").to_ascii_lowercase();
let langs = langs
// split colon separated entries
.split(':')
// strip codeset ("utf8" in "C.utf8")
.map(|s| s.split('.').next().unwrap_or(s))
// filter out empty entries
.filter(|s| !s.is_empty())
// intern instrings in arena
.map(|s| ArenaString::from_str(arena, s));
locales.extend(langs);
if !locales.is_empty() {
break;
}
}
}
dbg!(&locales);
locales
}"zh" => LangId::zh_hans, |
|
Maybe it should be changed to this? pub fn preferred_languages(arena: &Arena) -> Vec<ArenaString<'_>, &Arena> {
let mut locales = Vec::new_in(arena);
for key in ["LANGUAGE", "LC_ALL", "LANG"] {
if let Ok(langs) = std::env::var(key) {
let langs_str = langs.replace('_', "-").to_ascii_lowercase();
let langs = langs_str
// split colon separated entries
.split(':')
// strip codeset ("utf8" in "C.utf8")
.map(|s| s.split('.').next().unwrap_or(s))
// filter out empty entries
.filter(|s| !s.is_empty())
// intern instrings in arena
.map(|s| ArenaString::from_str(arena, s));
locales.extend(langs);
let Some((lang, _)) = langs_str.split_once('-') else {
continue;
};
locales.push(ArenaString::from_str(arena, lang));
if !locales.is_empty() {
break;
}
}
}
dbg!(&locales);
locales
} |
7dc8f4b to
81e7253
Compare
In Linux, it is possible for the `LANGUAGE` variable to exist but have a empty value
81e7253 to
33f12a6
Compare
|
FYI we squash all our PRs (to keep our history clean). You can absolutely feel free to just keep pushing commits into this PR. 🙂 |
hmm... Mostly it seems like all the problems I want fixed should be fixed in #85 |
lhecker
left a comment
There was a problem hiding this comment.
Thank you for fixing this! I'll try to merge in the other PR as soon as I can.
|
...I now realize why you replaced |
In Linux, it is possible for the `LANGUAGE` variable to exist but have an empty value.
In Linux, it is possible for the `LANGUAGE` variable to exist but have an empty value.
In Linux, it is possible for the
LANGUAGEvariable to exist but have a empty value,Before:
After: