[Libreoffice-commits] core.git: cui/source desktop/source include/svl svl/source

Caolán McNamara caolanm at redhat.com
Wed Sep 28 10:42:38 UTC 2016


 cui/source/options/optgdlg.cxx        |   13 ++++++++-
 desktop/source/app/langselect.cxx     |   47 +++-------------------------------
 include/svl/languageoptions.hxx       |    3 ++
 svl/source/config/languageoptions.cxx |   32 +++++++++++++++++++++++
 4 files changed, 52 insertions(+), 43 deletions(-)

New commits:
commit 219aae1cea7ba88d5a4503f8070566755efd3aef
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Sep 28 10:26:00 2016 +0100

    Resolves: tdf#96748 'Default Language' show current ui lang not new default
    
    i.e. if you select it, then the General::UILocale is unset and a new
    default generated based on the L10N::UILocale and what langpacks are installed
    but what the entry string claims is "Default - Current Language", rather than
    "Default - The Language That Will Be Used", so split out the language selection
    code into a reusable bit and use that to get the name of the language which will
    be selected if this entry is used
    
    Change-Id: I13d901c9a47ef213aea86417501114d4231efae5

diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index 4c59db2..fcbe8c9 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 a8309e5..9b52d8a4 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 3f1cd0e..f223904 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 92cbd67..bee71bb 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: */


More information about the Libreoffice-commits mailing list