diff options
-rw-r--r-- | cui/source/options/optgdlg.cxx | 13 | ||||
-rw-r--r-- | desktop/source/app/langselect.cxx | 47 | ||||
-rw-r--r-- | include/svl/languageoptions.hxx | 3 | ||||
-rw-r--r-- | svl/source/config/languageoptions.cxx | 32 |
4 files changed, 52 insertions, 43 deletions
diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx index 4c59db28ebe3..fcbe8c9ce338 100644 --- a/cui/source/options/optgdlg.cxx +++ b/cui/source/options/optgdlg.cxx @@ -69,6 +69,7 @@ #include <unotools/searchopt.hxx> #include <sal/macros.h> #include <officecfg/Office/Common.hxx> +#include <officecfg/Setup.hxx> #include <comphelper/configuration.hxx> #include <com/sun/star/configuration/theDefaultProvider.hpp> @@ -1103,6 +1104,16 @@ static OUString lcl_getDatePatternsConfigString( const LocaleDataWrapper& rLocal return aBuf.makeStringAndClear(); } +namespace +{ + //what ui language will be selected by default if the user override of General::UILocale is unset ? + LanguageTag GetInstalledLocaleForSystemUILanguage() + { + css::uno::Sequence<OUString> inst(officecfg::Setup::Office::InstalledLocales::get()->getElementNames()); + return LanguageTag(getInstalledLocaleForSystemUILanguage(inst)).makeFallback(); + } +} + OfaLanguagesTabPage::OfaLanguagesTabPage(vcl::Window* pParent, const SfxItemSet& rSet) : SfxTabPage(pParent,"OptLanguagesPage","cui/ui/optlanguagespage.ui", &rSet) , pLangConfig(new LanguageConfig_Impl) @@ -1137,7 +1148,7 @@ OfaLanguagesTabPage::OfaLanguagesTabPage(vcl::Window* pParent, const SfxItemSet& OUString aUILang = m_sSystemDefaultString + " - " + - SvtLanguageTable::GetLanguageString( Application::GetSettings().GetUILanguageTag().getLanguageType(), true ); + SvtLanguageTable::GetLanguageString(GetInstalledLocaleForSystemUILanguage().getLanguageType(), true); m_pUserInterfaceLB->InsertEntry(aUILang); m_pUserInterfaceLB->SetEntryData(0, nullptr); diff --git a/desktop/source/app/langselect.cxx b/desktop/source/app/langselect.cxx index a8309e5987ba..9b52d8a42fe9 100644 --- a/desktop/source/app/langselect.cxx +++ b/desktop/source/app/langselect.cxx @@ -49,28 +49,6 @@ namespace { OUString foundLocale; -OUString getInstalledLocale( - css::uno::Sequence<OUString> const & installed, OUString const & locale) -{ - if (locale.isEmpty()) - return OUString(); // do not attempt to resolve anything - - for (sal_Int32 i = 0; i != installed.getLength(); ++i) { - if (installed[i] == locale) { - return installed[i]; - } - } - ::std::vector<OUString> fallbacks( LanguageTag( locale).getFallbackStrings( false)); - for (OUString & rf : fallbacks) { - for (sal_Int32 i = 0; i != installed.getLength(); ++i) { - if (installed[i] == rf) { - return installed[i]; - } - } - } - return OUString(); -} - void setMsLangIdFallback(OUString const & locale) { // #i32939# setting of default document language // See #i42730# for rules for determining source of settings @@ -101,24 +79,16 @@ OUString getEmergencyLocale() { officecfg::Setup::Office::InstalledLocales::get()-> getElementNames()); OUString locale( - getInstalledLocale( + getInstalledLocaleForLanguage( inst, officecfg::Office::Linguistic::General::UILocale::get())); if (!locale.isEmpty()) { return locale; } - locale = getInstalledLocale( - inst, officecfg::System::L10N::UILocale::get()); - if (!locale.isEmpty()) { - return locale; - } - locale = getInstalledLocale(inst, "en-US"); + locale = getInstalledLocaleForSystemUILanguage(inst); if (!locale.isEmpty()) { return locale; } - if (inst.hasElements()) { - return inst[0]; - } } catch (css::uno::Exception & e) { SAL_WARN("desktop.app", "ignoring Exception \"" << e.Message << "\""); } @@ -135,7 +105,7 @@ bool prepareLocale() { officecfg::Setup::Office::InstalledLocales::get()->getElementNames()); OUString locale(officecfg::Office::Linguistic::General::UILocale::get()); if (!locale.isEmpty()) { - locale = getInstalledLocale(inst, locale); + locale = getInstalledLocaleForLanguage(inst, locale); if (locale.isEmpty()) { // Selected language is not/no longer installed: try { @@ -153,21 +123,14 @@ bool prepareLocale() { } bool cmdLanguage = false; if (locale.isEmpty()) { - locale = getInstalledLocale( + locale = getInstalledLocaleForLanguage( inst, Desktop::GetCommandLineArgs().GetLanguage()); if (!locale.isEmpty()) { cmdLanguage = true; } } if (locale.isEmpty()) { - locale = getInstalledLocale( - inst, officecfg::System::L10N::UILocale::get()); - } - if (locale.isEmpty()) { - locale = getInstalledLocale(inst, "en-US"); - } - if (locale.isEmpty() && inst.hasElements()) { - locale = inst[0]; + locale = getInstalledLocaleForSystemUILanguage(inst); } if (locale.isEmpty()) { return false; diff --git a/include/svl/languageoptions.hxx b/include/svl/languageoptions.hxx index 3f1cd0e1a933..f223904a2f6e 100644 --- a/include/svl/languageoptions.hxx +++ b/include/svl/languageoptions.hxx @@ -132,6 +132,9 @@ public: bool isCJKKeyboardLayoutInstalled() const; }; +OUString SVL_DLLPUBLIC getInstalledLocaleForLanguage(css::uno::Sequence<OUString> const & installed, OUString const & locale); +OUString SVL_DLLPUBLIC getInstalledLocaleForSystemUILanguage(css::uno::Sequence<OUString> const & installed); + #endif // INCLUDED_SVL_LANGUAGEOPTIONS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/languageoptions.cxx b/svl/source/config/languageoptions.cxx index 92cbd67d3992..bee71bb4534e 100644 --- a/svl/source/config/languageoptions.cxx +++ b/svl/source/config/languageoptions.cxx @@ -27,6 +27,7 @@ #include <rtl/instance.hxx> #include <com/sun/star/i18n/ScriptType.hpp> #include <unotools/syslocale.hxx> +#include "officecfg/System.hxx" #ifdef _WIN32 #include <windows.h> @@ -264,4 +265,35 @@ bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN); } +OUString getInstalledLocaleForLanguage(css::uno::Sequence<OUString> const & installed, OUString const & locale) +{ + if (locale.isEmpty()) + return OUString(); // do not attempt to resolve anything + + for (sal_Int32 i = 0; i != installed.getLength(); ++i) { + if (installed[i] == locale) { + return installed[i]; + } + } + std::vector<OUString> fallbacks(LanguageTag(locale).getFallbackStrings(false)); + for (OUString & rf : fallbacks) { + for (sal_Int32 i = 0; i != installed.getLength(); ++i) { + if (installed[i] == rf) { + return installed[i]; + } + } + } + return OUString(); +} + +OUString getInstalledLocaleForSystemUILanguage(const css::uno::Sequence<OUString>& rLocaleElementNames) +{ + OUString locale = getInstalledLocaleForLanguage(rLocaleElementNames, officecfg::System::L10N::UILocale::get()); + if (locale.isEmpty()) + locale = getInstalledLocaleForLanguage(rLocaleElementNames, "en-US"); + if (locale.isEmpty() && rLocaleElementNames.hasElements()) + locale = rLocaleElementNames[0]; + return locale; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |