From ef3e6bebe4ce116669af9401dd52a415a3b0dc4b Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Thu, 13 Feb 2025 17:24:36 -0600 Subject: [PATCH] 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 5009e134313bd7b978f1c56d5d94a77ab53ac85b, 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 _. --- osdep/language-posix.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/osdep/language-posix.c b/osdep/language-posix.c index 8fd68c6420..dc2cf11912 100644 --- a/osdep/language-posix.c +++ b/osdep/language-posix.c @@ -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; } }