diff --git a/minidlna.c b/minidlna.c index 6c5110a..724f8ea 100644 --- a/minidlna.c +++ b/minidlna.c @@ -468,9 +468,21 @@ static int strtobool(const char *str) static void init_nls(void) { #ifdef ENABLE_NLS - setlocale(LC_MESSAGES, ""); - setlocale(LC_CTYPE, "en_US.utf8"); - DPRINTF(E_DEBUG, L_GENERAL, "Using locale dir %s\n", bindtextdomain("minidlna", getenv("TEXTDOMAINDIR"))); + const char *messages, *ctype, *locale_dir; + + ctype = setlocale(LC_CTYPE, ""); + if (!ctype || !strcmp(ctype, "C")) + ctype = setlocale(LC_CTYPE, "en_US.utf8"); + if (!ctype) + DPRINTF(E_WARN, L_GENERAL, "Unset locale\n"); + else if (!strstr(ctype, "utf8") && !strstr(ctype, "UTF8") && + !strstr(ctype, "utf-8") && !strstr(ctype, "UTF-8")) + DPRINTF(E_WARN, L_GENERAL, "Using unsupported non-utf8 locale '%s'\n", ctype); + messages = setlocale(LC_MESSAGES, ""); + if (!messages) + messages = "unset"; + locale_dir = bindtextdomain("minidlna", getenv("TEXTDOMAINDIR")); + DPRINTF(E_DEBUG, L_GENERAL, "Using locale dir '%s' and locale langauge %s/%s\n", locale_dir, messages, ctype); textdomain("minidlna"); #endif }