language-posix: replace '_' subtag separator with '-'

Internally, mpv uses '-' as a separator for language codes like
specifying the region/variant for the language. However, the posix
environment variables for this separate using a _. Since
5009e13431, support for the _ separator
was dropped which meant that --subs-match-os-language actually didn't
work on linux/bsd at all (mac has its own separate implementation).
Instead of adding _ back to the function, it makes more sense to just
replace _ with - while we parse through the languages since this
implementation of mp_get_user_langs is the only one that separates with
_.
This commit is contained in:
Dudemanguy committed 2025-02-16 00:47:13 +00:00
1 parent f94b44c8e5
commit ef3e6bebe4
1 file changed
+13 -2
+13 -2
View File
@@ -39,7 +39,12 @@ char **mp_get_user_langs(void)
for (const char *langList = getenv("LANGUAGE"); langList && *langList;) {
size_t len = strcspn(langList, ":");
MP_TARRAY_GROW(NULL, ret, nb);
ret[nb++] = talloc_strndup(ret, langList, len);
char *lang = talloc_strndup(ret, langList, len);
for (int i = 0; i < len; i++) {
if (lang[i] == '_')
lang[i] = '-';
}
ret[nb++] = lang;
langList += len;
while (*langList == ':')
langList++;
@@ -56,7 +61,13 @@ char **mp_get_user_langs(void)
}
MP_TARRAY_GROW(NULL, ret, nb);
ret[nb++] = talloc_strndup(ret, envval, len);
char *lang = talloc_strndup(ret, envval, len);
for (int j = 0; j < len; j++) {
if (lang[j] == '_')
lang[j] = '-';
}
ret[nb++] = lang;
}
}