From 520de165fb429af581e4a98b48756f1ad1fdfbd8 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 21 Dec 2015 11:45:10 -0800 Subject: [PATCH] nls: Rework NLS init to work with non-en_US locales. We shouldn't blindly set the LC_CTYPE to en_US.utf8, because the user may not have it installed. So if the user already has a utf8 locale defined, just use it for LC_CTYPE. Fixed: SF Bug #87 (Problem of accentuation) --- minidlna.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 }