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
This commit is contained in:
parent
58fab0b920
commit
3810f28d78
@ -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)
|
||||
|
@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \
|
||||
comphelper \
|
||||
cppu \
|
||||
cppuhelper \
|
||||
i18nlangtag \
|
||||
sal \
|
||||
sc \
|
||||
scfilt \
|
||||
|
@ -2764,7 +2764,7 @@ void DesktopLOKTest::testSpellcheckerMultiView()
|
||||
SvtSysLocaleOptions aSysLocaleOptions;
|
||||
aSysLocaleOptions.SetLocaleConfigString(aLangISO);
|
||||
aSysLocaleOptions.SetUILocaleConfigString(aLangISO);
|
||||
comphelper::LibreOfficeKit::setLanguageTag(aLangISO, true);
|
||||
comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLangISO, true));
|
||||
|
||||
auto aSavedSettings = Application::GetSettings();
|
||||
std::unique_ptr<Resetter> pResetter(
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <rtl/bootstrap.hxx>
|
||||
#include <rtl/strbuf.hxx>
|
||||
#include <rtl/uri.hxx>
|
||||
#include <svl/zforlist.hxx>
|
||||
#include <cppuhelper/bootstrap.hxx>
|
||||
#include <comphelper/base64.hxx>
|
||||
#include <comphelper/dispatchcommand.hxx>
|
||||
@ -2078,6 +2079,14 @@ void paintTileIOS(LibreOfficeKitDocument* pThis,
|
||||
}
|
||||
#endif
|
||||
|
||||
void setLanguageAndLocale(OUString const & aLangISO)
|
||||
{
|
||||
SvtSysLocaleOptions aLocalOptions;
|
||||
aLocalOptions.SetLocaleConfigString(aLangISO);
|
||||
aLocalOptions.SetUILocaleConfigString(aLangISO);
|
||||
aLocalOptions.Commit();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Wonder global state ...
|
||||
@ -2134,13 +2143,17 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
|
||||
|
||||
if (!aLanguage.isEmpty())
|
||||
{
|
||||
SfxLokHelper::setDefaultLanguage(aLanguage);
|
||||
// Set the LOK language tag, used for dialog tunneling.
|
||||
comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage));
|
||||
comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage));
|
||||
|
||||
SAL_INFO("lok", "Set document language to " << aLanguage);
|
||||
// use with care - it sets it for the entire core, not just the
|
||||
// document
|
||||
SvtSysLocaleOptions aSysLocaleOptions;
|
||||
aSysLocaleOptions.SetLocaleConfigString(aLanguage);
|
||||
aSysLocaleOptions.SetUILocaleConfigString(aLanguage);
|
||||
// Set the LOK language tag, used for dialog tunneling.
|
||||
comphelper::LibreOfficeKit::setLanguageTag(aSysLocaleOptions.GetLanguageTag());
|
||||
setLanguageAndLocale(aLanguage);
|
||||
// Need to reset the static initialized values
|
||||
SvNumberFormatter::resetTheCurrencyTable();
|
||||
}
|
||||
|
||||
uno::Sequence<css::beans::PropertyValue> aFilterOptions(2);
|
||||
@ -4885,6 +4898,7 @@ static int doc_createViewWithOptions(LibreOfficeKitDocument* pThis,
|
||||
{
|
||||
// Set the LOK language tag, used for dialog tunneling.
|
||||
comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage));
|
||||
comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage));
|
||||
}
|
||||
|
||||
int nId = SfxLokHelper::createView();
|
||||
@ -4962,7 +4976,9 @@ static void doc_setViewLanguage(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*p
|
||||
SolarMutexGuard aGuard;
|
||||
SetLastExceptionMsg();
|
||||
|
||||
SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8));
|
||||
OUString sLanguage = OStringToOUString(language, RTL_TEXTENCODING_UTF8);
|
||||
SfxLokHelper::setViewLanguage(nId, sLanguage);
|
||||
SfxLokHelper::setViewLocale(nId, sLanguage);
|
||||
}
|
||||
|
||||
|
||||
@ -5508,15 +5524,6 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
|
||||
return convertOUString(ReplaceStringHookProc(sVersionStrTemplate));
|
||||
}
|
||||
|
||||
static void force_c_locale()
|
||||
{
|
||||
// force locale (and resource files loaded) to en-US
|
||||
OUString aLangISO("en-US");
|
||||
SvtSysLocaleOptions aLocalOptions;
|
||||
aLocalOptions.SetLocaleConfigString(aLangISO);
|
||||
aLocalOptions.SetUILocaleConfigString(aLangISO);
|
||||
}
|
||||
|
||||
static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
|
||||
{
|
||||
OString aBuffer = "Unexpected dialog: " +
|
||||
@ -5987,7 +5994,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
|
||||
Application::ReleaseSolarMutex();
|
||||
}
|
||||
|
||||
force_c_locale();
|
||||
setLanguageAndLocale("en-US");
|
||||
}
|
||||
|
||||
if (eStage != PRE_INIT)
|
||||
|
@ -94,8 +94,11 @@ COMPHELPER_DLLPUBLIC bool isViewIdForVisCursorInvalidation();
|
||||
/// Set whether clients want viewId in visible cursor invalidation payload.
|
||||
COMPHELPER_DLLPUBLIC void setViewIdForVisCursorInvalidation(bool bViewIdForVisCursorInvalidation);
|
||||
|
||||
/// Update the current LOK's language.
|
||||
COMPHELPER_DLLPUBLIC void setLanguageTag(const OUString& lang, bool bCanonicalize = false);
|
||||
/// Update the current LOK's locale.
|
||||
COMPHELPER_DLLPUBLIC void setLocale(const LanguageTag& languageTag);
|
||||
/// Get the current LOK's locale.
|
||||
COMPHELPER_DLLPUBLIC const LanguageTag& getLocale();
|
||||
|
||||
/// Update the current LOK's language.
|
||||
COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag);
|
||||
/// Get the current LOK's language.
|
||||
|
@ -54,8 +54,14 @@ public:
|
||||
static std::size_t getViewsCount();
|
||||
/// Get viewIds of all existing views.
|
||||
static bool getViewIds(int* pArray, size_t nSize);
|
||||
/// Get the default language that should be used for views
|
||||
static LanguageTag getDefaultLanguage();
|
||||
/// Set language of the given view.
|
||||
static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag);
|
||||
/// Set the default language for views.
|
||||
static void setDefaultLanguage(const OUString& rBcp47LanguageTag);
|
||||
/// Set the locale for the given view.
|
||||
static void setViewLocale(int nId, const OUString& rBcp47LanguageTag);
|
||||
/// Iterate over any view shell, except pThisViewShell, passing it to the f function.
|
||||
template<typename ViewShellType, typename FunctionType>
|
||||
static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f);
|
||||
|
@ -151,6 +151,7 @@ friend class SfxPrinterController;
|
||||
bool bNoNewWindow;
|
||||
bool mbPrinterSettingsModified;
|
||||
LanguageTag maLOKLanguageTag;
|
||||
LanguageTag maLOKLocale;
|
||||
|
||||
protected:
|
||||
virtual void Activate(bool IsMDIActivate) override;
|
||||
@ -346,6 +347,11 @@ public:
|
||||
void SetLOKLanguageTag(const OUString& rBcp47LanguageTag);
|
||||
/// Get the LibreOfficeKit language of this view.
|
||||
const LanguageTag& GetLOKLanguageTag() const { return maLOKLanguageTag; }
|
||||
|
||||
/// Set the LibreOfficeKit locale of this view.
|
||||
void SetLOKLocale(const OUString& rBcp47LanguageTag);
|
||||
/// Get the LibreOfficeKit locale of this view.
|
||||
const LanguageTag& GetLOKLocale() const { return maLOKLocale; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -730,6 +730,8 @@ public:
|
||||
/// Return the decimal separator matching the given locale / LanguageType.
|
||||
OUString GetLangDecimalSep( LanguageType nLang ) const;
|
||||
|
||||
static void resetTheCurrencyTable();
|
||||
|
||||
/// Return a NfCurrencyTable with pointers to <type>NfCurrencyEntry</type> entries
|
||||
static const NfCurrencyTable& GetTheCurrencyTable();
|
||||
|
||||
|
@ -63,6 +63,11 @@ private:
|
||||
int DisableCallbacks::m_nDisabled = 0;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
static LanguageTag g_defaultLanguageTag("en-US", true);
|
||||
}
|
||||
|
||||
int SfxLokHelper::createView()
|
||||
{
|
||||
SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
|
||||
@ -112,8 +117,9 @@ void SfxLokHelper::setView(int nId)
|
||||
{
|
||||
DisableCallbacks dc;
|
||||
|
||||
// update the current LOK language for the dialog tunneling
|
||||
// update the current LOK language and locale for the dialog tunneling
|
||||
comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
|
||||
comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale());
|
||||
|
||||
if (pViewShell == SfxViewShell::Current())
|
||||
return;
|
||||
@ -166,6 +172,16 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
|
||||
return true;
|
||||
}
|
||||
|
||||
LanguageTag SfxLokHelper::getDefaultLanguage()
|
||||
{
|
||||
return g_defaultLanguageTag;
|
||||
}
|
||||
|
||||
void SfxLokHelper::setDefaultLanguage(const OUString& rBcp47LanguageTag)
|
||||
{
|
||||
g_defaultLanguageTag = LanguageTag(rBcp47LanguageTag, true);
|
||||
}
|
||||
|
||||
void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag)
|
||||
{
|
||||
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
|
||||
@ -180,6 +196,20 @@ void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag)
|
||||
}
|
||||
}
|
||||
|
||||
void SfxLokHelper::setViewLocale(int nId, const OUString& rBcp47LanguageTag)
|
||||
{
|
||||
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
|
||||
|
||||
for (SfxViewShell* pViewShell : rViewArr)
|
||||
{
|
||||
if (pViewShell->GetViewShellId() == ViewShellId(nId))
|
||||
{
|
||||
pViewShell->SetLOKLocale(rBcp47LanguageTag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static OString lcl_escapeQuotes(const OString &rStr)
|
||||
{
|
||||
if (rStr.getLength() < 1)
|
||||
|
@ -1069,7 +1069,8 @@ SfxViewShell::SfxViewShell
|
||||
, pWindow(nullptr)
|
||||
, bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW )
|
||||
, mbPrinterSettingsModified(false)
|
||||
, maLOKLanguageTag("en-US", true)
|
||||
, maLOKLanguageTag(LANGUAGE_NONE)
|
||||
, maLOKLocale(LANGUAGE_NONE)
|
||||
{
|
||||
|
||||
SetMargin( pViewFrame->GetMargin_Impl() );
|
||||
@ -1083,6 +1084,9 @@ SfxViewShell::SfxViewShell
|
||||
|
||||
if (comphelper::LibreOfficeKit::isActive())
|
||||
{
|
||||
maLOKLanguageTag = SfxLokHelper::getDefaultLanguage();
|
||||
maLOKLocale = SfxLokHelper::getDefaultLanguage();
|
||||
|
||||
vcl::Window* pFrameWin = pViewFrame->GetWindow().GetFrameWindow();
|
||||
if (pFrameWin && !pFrameWin->GetLOKNotifier())
|
||||
pFrameWin->SetLOKNotifier(this, true);
|
||||
@ -1506,6 +1510,11 @@ void SfxViewShell::SetLOKLanguageTag(const OUString& rBcp47LanguageTag)
|
||||
maLOKLanguageTag = aFallbackTag;
|
||||
}
|
||||
|
||||
void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag)
|
||||
{
|
||||
maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback();
|
||||
}
|
||||
|
||||
void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const
|
||||
{
|
||||
}
|
||||
|
@ -3413,6 +3413,16 @@ sal_uInt16 SvNumberFormatter::GetYear2000Default()
|
||||
return 1930;
|
||||
}
|
||||
|
||||
// static
|
||||
void SvNumberFormatter::resetTheCurrencyTable()
|
||||
{
|
||||
SAL_INFO("svl", "Resetting the currency table.");
|
||||
|
||||
nSystemCurrencyPosition = 0;
|
||||
bCurrencyTableInitialized = false;
|
||||
|
||||
GetFormatterRegistry().ConfigurationChanged(nullptr, ConfigurationHints::Locale | ConfigurationHints::Currency | ConfigurationHints::DatePatterns);
|
||||
}
|
||||
|
||||
// static
|
||||
const NfCurrencyTable& SvNumberFormatter::GetTheCurrencyTable()
|
||||
|
@ -171,7 +171,7 @@ SvtSysLocaleOptions& SvtSysLocale::GetOptions() const
|
||||
const LanguageTag& SvtSysLocale::GetLanguageTag() const
|
||||
{
|
||||
if (comphelper::LibreOfficeKit::isActive())
|
||||
return comphelper::LibreOfficeKit::getLanguageTag();
|
||||
return comphelper::LibreOfficeKit::getLocale();
|
||||
|
||||
return pImpl->aSysLocaleOptions.GetRealLanguageTag();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user