summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-12-06 13:21:50 +0100
committerEike Rathke <erack@redhat.com>2017-12-07 13:05:22 +0100
commitbfe2fb8ceed6643574010bf7b40f04d149f0fd6d (patch)
tree0668b001ed6dc0a4b664610f9786860631ce89f3
parentd17dfb3dc1cc7fd91ede9a58337d89e38fd3b022 (diff)
Handle conversion from glibc locale to BCP 47 language tag
The backend's ImplGetLocale() didn't handle variants, so ca_ES@valencia ended up as ca-ES instead of ca-ES-valencia, which made a difference with for example the UI language being set to Default resulting in only ca instead of ca-valencia, which then is also written to /org.openoffice.Setup/L10N/ooLocale during startup and obtained later. This only for the *iX branch, no idea if and what could be adjusted for Windows or MacOSX. Change-Id: I050f6f643571ccdc669fb91b06f3bb516f96e8d5 Reviewed-on: https://gerrit.libreoffice.org/45946 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit c2bd06120b932bf3757f19bdf8c8d9ee8a31f557) Reviewed-on: https://gerrit.libreoffice.org/45980
-rw-r--r--shell/Library_localebe.mk1
-rw-r--r--shell/source/backends/localebe/localebackend.cxx34
2 files changed, 28 insertions, 7 deletions
diff --git a/shell/Library_localebe.mk b/shell/Library_localebe.mk
index 7c4931b2ce39..b8d8aba8f15c 100644
--- a/shell/Library_localebe.mk
+++ b/shell/Library_localebe.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_Library_use_libraries,localebe1,\
cppu \
cppuhelper \
sal \
+ i18nlangtag \
))
$(eval $(call gb_Library_set_componentfile,localebe1,shell/source/backends/localebe/localebe1))
diff --git a/shell/source/backends/localebe/localebackend.cxx b/shell/source/backends/localebe/localebackend.cxx
index 7ff388a1f26d..3392bb73cfc0 100644
--- a/shell/source/backends/localebe/localebackend.cxx
+++ b/shell/source/backends/localebe/localebackend.cxx
@@ -28,6 +28,8 @@
#include <osl/time.h>
#include <rtl/character.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
+#include <i18nlangtag/languagetag.hxx>
+#include <i18nlangtag/mslangid.hxx>
#include <stdio.h>
@@ -184,16 +186,19 @@ static css::beans::Optional<css::uno::Any> ImplGetLocale(char const * category)
const char *cp;
const char *uscore = nullptr;
+ const char *end = nullptr;
// locale string have the format lang[_ctry][.encoding][@modifier]
- // we are only interested in the first two items, so we handle
- // '.' and '@' as string end.
+ // Let LanguageTag handle all conversion, but do a sanity and length check
+ // first.
+ // For the fallback we are only interested in the first two items, so we
+ // handle '.' and '@' as string end for that.
for (cp = locale; *cp; cp++)
{
- if (*cp == '_')
+ if (*cp == '_' && !uscore)
uscore = cp;
- if (*cp == '.' || *cp == '@')
- break;
+ if ((*cp == '.' || *cp == '@') && !end)
+ end = cp;
if (!rtl::isAscii(static_cast<unsigned char>(*cp))) {
SAL_INFO("shell", "locale env var with non-ASCII content");
return {false, {}};
@@ -205,16 +210,31 @@ static css::beans::Optional<css::uno::Any> ImplGetLocale(char const * category)
return {false, {}};
}
+ // This is a tad awkward.. but the easiest way to obtain what we're
+ // actually interested in. For example this also converts
+ // "ca_ES.UTF-8@valencia" to "ca-ES-valencia".
+ const OString aLocaleStr(locale);
+ const LanguageType nLang = MsLangId::convertUnxByteStringToLanguage( aLocaleStr);
+ if (nLang != LANGUAGE_DONTKNOW)
+ {
+ const OUString aLangTagStr( LanguageTag::convertToBcp47( nLang));
+ return {true, css::uno::Any(aLangTagStr)};
+ }
+
+ // As a fallback, strip encoding and modifier and return just a
+ // language-country combination and let the caller handle unknowns.
OUStringBuffer aLocaleBuffer;
+ if (!end)
+ end = cp;
if( uscore != nullptr )
{
aLocaleBuffer.appendAscii(locale, uscore++ - locale);
aLocaleBuffer.append("-");
- aLocaleBuffer.appendAscii(uscore, cp - uscore);
+ aLocaleBuffer.appendAscii(uscore, end - uscore);
}
else
{
- aLocaleBuffer.appendAscii(locale, cp - locale);
+ aLocaleBuffer.appendAscii(locale, end - locale);
}
return {true, css::uno::Any(aLocaleBuffer.makeStringAndClear())};