diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-02-24 08:07:12 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-02-25 09:25:33 +0100 |
commit | 3810f28d784ff71d4c6d68557e70bd80c1d1d99c (patch) | |
tree | 6693669512264f402e9169107141150c2347bd7c /comphelper | |
parent | 58fab0b920303e58d3ac3be28b22763970085f02 (diff) |
Fix currency symbol selection in Calc on mobile
In LOK we use one language identifier for both - UI language and
the locale used. This is a problem when we determine that we a
language for UI is not available and fall-back to the default
"en-US" langauge, which also changes the locale. This introduces
a separate variable that stores the language tag for the locale
independently to the language.
Another problem is that in some cases we don't reset the staticly
initialized data, when the new document is loaded, which is on
the other hand used to define which currency symbol is used as
SYSTEM locale. That can in some cases select the wrong currency
symbol even when we changed the locale to something else. This fix
introduces a reset function, which is triggered on every document
load.
Change-Id: I55c7f467600a832895f94346f8bf11a6ef6a1e49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89320
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89343
Tested-by: Jenkins
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/lok.cxx | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index f339db2657dc..2deb105d8e02 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -35,7 +35,55 @@ static bool g_bLocalRendering(false); static Compat g_eCompatFlags(Compat::none); -static LanguageTag g_aLanguageTag("en-US", true); +namespace +{ + +class LanguageAndLocale +{ +private: + LanguageTag maLanguageTag; + LanguageTag maLocaleLanguageTag; + +public: + + LanguageAndLocale() + : maLanguageTag(LANGUAGE_NONE) + , maLocaleLanguageTag(LANGUAGE_NONE) + {} + + const LanguageTag& getLanguage() + { + return maLanguageTag; + } + + void setLanguage(const LanguageTag& rLanguageTag) + { + if (maLanguageTag != rLanguageTag) + { + SAL_INFO("comphelper.lok", "Setting language from " << maLanguageTag.getBcp47() << " to " << rLanguageTag.getBcp47()); + maLanguageTag = rLanguageTag; + } + } + + const LanguageTag& getLocale() + { + return maLocaleLanguageTag; + } + + void setLocale(const LanguageTag& rLocaleLanguageTag) + { + if (maLocaleLanguageTag != rLocaleLanguageTag) + { + SAL_INFO("comphelper.lok", "Setting locale from " << maLanguageTag.getBcp47() << " to " << rLocaleLanguageTag.getBcp47()); + maLocaleLanguageTag = rLocaleLanguageTag; + } + } + +}; + +} + +static LanguageAndLocale g_aLanguageAndLocale; /// Scaling of the cairo canvas painting for hi-dpi static double g_fDPIScale(1.0); @@ -153,23 +201,28 @@ void setCompatFlag(Compat flag) { g_eCompatFlags = static_cast<Compat>(g_eCompat bool isCompatFlagSet(Compat flag) { return (g_eCompatFlags & flag) == flag; } -void setLanguageTag(const OUString& lang, bool bCanonicalize) +void setLocale(const LanguageTag& rLanguageTag) { - g_aLanguageTag = LanguageTag(lang, bCanonicalize); + g_aLanguageAndLocale.setLocale(rLanguageTag); } -void setLanguageTag(const LanguageTag& languageTag) +const LanguageTag& getLocale() { - if (g_aLanguageTag != languageTag) - { - SAL_INFO("comphelper.lok", "setLanguageTag: from " << g_aLanguageTag.getBcp47() << " to " << languageTag.getBcp47()); - g_aLanguageTag = languageTag; - } + const LanguageTag& rLocale = g_aLanguageAndLocale.getLocale(); + SAL_WARN_IF(rLocale.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Locale not set"); + return rLocale; +} + +void setLanguageTag(const LanguageTag& rLanguageTag) +{ + g_aLanguageAndLocale.setLanguage(rLanguageTag); } const LanguageTag& getLanguageTag() { - return g_aLanguageTag; + const LanguageTag& rLanguage = g_aLanguageAndLocale.getLanguage(); + SAL_WARN_IF(rLanguage.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Language not set"); + return rLanguage; } bool isWhitelistedLanguage(const OUString& lang) |