From f42398e714b1dc0a24a8f5d9852f13f0565e49d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 7 Feb 2010 17:34:59 +0000 Subject: [PATCH] Workaround encoding issues on Mac OS X: when Eliot is started from the dock, the LANG variable is not set. So retrieve the language from the preferences, and force encoding to UTF-8. --- qt/main.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/qt/main.cpp b/qt/main.cpp index e3ee652..c912d7f 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -29,8 +29,7 @@ # include #endif #ifdef __APPLE__ -# include -# include +# include #endif using std::string; @@ -38,9 +37,44 @@ using std::string; int main(int argc, char **argv) { + // On Mac, running Eliot from the dock does not automatically set the LANG + // variable, so we do it ourselves. + // Note: The following block of code is copied from VLC, and slightly + // modified by me (original author: Pierre d'Herbemont) +#if defined(ENABLE_NLS) && defined(__APPLE__) + /* Check if $LANG is set. */ + if (NULL == getenv("LANG")) + { + // Retrieve the preferred language as chosen in System Preferences.app + // (note that CFLocaleCopyCurrent() is not used because it returns the + // preferred locale not language) + CFArrayRef all_locales = CFLocaleCopyAvailableLocaleIdentifiers(); + CFArrayRef preferred_locales = CFBundleCopyLocalizationsForPreferences(all_locales, NULL); + + if (preferred_locales) + { + if (CFArrayGetCount(preferred_locales)) + { + char psz_locale[50]; + CFStringRef user_language_string_ref = (CFStringRef) CFArrayGetValueAtIndex(preferred_locales, 0); + CFStringGetCString(user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8); + setenv("LANG", psz_locale, 1); + } + CFRelease(preferred_locales); + } + CFRelease(all_locales); + } +#endif + + #ifdef HAVE_SETLOCALE // Set locale via LC_ALL setlocale(LC_ALL, ""); +#ifdef __APPLE__ + // FIXME: Ugly hack: we hardcode the encoding to UTF-8, because I don't + // know how to retrieve it properly + setlocale(LC_CTYPE, "UTF-8"); +#endif #endif QApplication app(argc, argv);