i18nlangtag/source/isolang/inunx.cxx | 37 +++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
New commits: commit f2c3c927021cd008366291e67606f6537e3e20be Author: Eike Rathke <er...@redhat.com> AuthorDate: Wed Dec 15 14:15:26 2021 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed Dec 15 16:53:40 2021 +0100 Resolves: tdf#146228 env-var $LANGUAGE can be a colon separated list Try to extract a first or second if first is empty. Ideally the sequence would be matched against available UI localizations, but that's simply not available at this stage. Change-Id: I37d0c289fe165c76a98086c63279aacf6856900c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126862 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/i18nlangtag/source/isolang/inunx.cxx b/i18nlangtag/source/isolang/inunx.cxx index 2f53ed3b349a..e8ad10059d24 100644 --- a/i18nlangtag/source/isolang/inunx.cxx +++ b/i18nlangtag/source/isolang/inunx.cxx @@ -39,11 +39,12 @@ static LanguageType nImplSystemUILanguage = LANGUAGE_DONTKNOW; // Get locale of category LC_CTYPE of environment variables -static const char* getLangFromEnvironment() +static const char* getLangFromEnvironment( bool& rbColonList ) { static const char* const pFallback = "C"; const char *pLang = nullptr; + rbColonList = false; pLang = getenv ( "LC_ALL" ); if (! pLang || pLang[0] == 0) pLang = getenv ( "LC_CTYPE" ); @@ -57,14 +58,18 @@ static const char* getLangFromEnvironment() // Get locale of category LC_MESSAGES of environment variables -static const char* getUILangFromEnvironment() +static const char* getUILangFromEnvironment( bool& rbColonList ) { static const char* const pFallback = "C"; const char *pLang = nullptr; + rbColonList = true; pLang = getenv ( "LANGUAGE" ); // respect the GNU extension if (! pLang || pLang[0] == 0) + { + rbColonList = false; pLang = getenv ( "LC_ALL" ); + } if (! pLang || pLang[0] == 0) pLang = getenv ( "LC_MESSAGES" ); if (! pLang || pLang[0] == 0) @@ -76,7 +81,7 @@ static const char* getUILangFromEnvironment() } -typedef const char * (*getLangFromEnv)(); +typedef const char * (*getLangFromEnv)( bool& rbColonList ); static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage, getLangFromEnv pGetLangFromEnv ) @@ -104,7 +109,31 @@ static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage, #endif } #else /* MACOSX */ - OString aUnxLang( pGetLangFromEnv() ); + bool bColonList = false; + OString aUnxLang( pGetLangFromEnv( bColonList)); + if (bColonList) + { + // Only a very simple "take first". If empty try second or keep empty. + sal_Int32 n = aUnxLang.indexOf(':'); + if (n >= 0) + { + sal_Int32 s = 0; + if (n == 0 && aUnxLang.getLength() > 1) + { + n = aUnxLang.indexOf(':', 1); + if (n < 0) + n = aUnxLang.getLength(); + if (n < 2) + s = n = 0; + else + { + s = 1; + --n; + } + } + aUnxLang = aUnxLang.copy(s,n); + } + } nLang = MsLangId::convertUnxByteStringToLanguage( aUnxLang ); OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); rSystemLanguage = nLang;