summaryrefslogtreecommitdiffstats
path: root/i18nlangtag
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2021-12-15 14:15:26 +0100
committerEike Rathke <erack@redhat.com>2021-12-15 18:48:12 +0100
commitaae69bafb680560d89cbe64db0c9df014d343c6e (patch)
tree85eb5b52a23d537cea90be5c378b196980e76611 /i18nlangtag
parentunset mpMenuBarWidget when it was destroyed along with its parent (diff)
downloadcore-aae69bafb680560d89cbe64db0c9df014d343c6e.tar.gz
core-aae69bafb680560d89cbe64db0c9df014d343c6e.zip
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 <erack@redhat.com> Tested-by: Jenkins (cherry picked from commit f2c3c927021cd008366291e67606f6537e3e20be) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126878
Diffstat (limited to 'i18nlangtag')
-rw-r--r--i18nlangtag/source/isolang/inunx.cxx37
1 files changed, 33 insertions, 4 deletions
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;