language-posix: as a fallback, treat "C" as "en"

If we see "C" in one of the language vars we check, don't treat it as a language tag.
Once we've checked everything, if we don't have any languages, but saw "C" anywhere, fall back on "en".
This commit is contained in:
rcombs 2023-07-23 14:46:28 -07:00 committed by sfan5
parent 4939570e17
commit 4ac5e6c810
1 changed files with 11 additions and 0 deletions

View File

@ -33,6 +33,7 @@ char **mp_get_user_langs(void)
size_t nb = 0;
char **ret = NULL;
bool has_c = false;
// Prefer anything we get from LANGUAGE first
for (const char *langList = getenv("LANGUAGE"); langList && *langList;) {
@ -49,11 +50,21 @@ char **mp_get_user_langs(void)
const char *envval = getenv(list[i]);
if (envval && *envval) {
size_t len = strcspn(envval, ".@");
if (!strncmp("C", envval, len)) {
has_c = true;
continue;
}
MP_TARRAY_GROW(NULL, ret, nb);
ret[nb++] = talloc_strndup(ret, envval, len);
}
}
if (has_c && !nb) {
MP_TARRAY_GROW(NULL, ret, nb);
ret[nb++] = talloc_strdup(ret, "en");
}
// Null-terminate the list
MP_TARRAY_APPEND(NULL, ret, nb, NULL);