Kaydet (Commit) c2bd0612 authored tarafından Eike Rathke's avatar Eike Rathke

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/45946Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 7265e75f
......@@ -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))
......
......@@ -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())};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment