[Libreoffice-commits] .: i18npool/inc i18npool/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 16 13:32:39 PST 2012


 i18npool/inc/i18npool/languagetag.hxx       |   10 ++++++
 i18npool/inc/i18npool/mslangid.hxx          |   11 +++++--
 i18npool/source/languagetag/languagetag.cxx |   43 ++++++++++++++++++++++++----
 3 files changed, 56 insertions(+), 8 deletions(-)

New commits:
commit 15e274a37c75eedb6e2fae07e4689cef67cdf2d7
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Nov 16 22:31:09 2012 +0100

    added LanguageTag::makeFallback()
    
    Change-Id: I6a89dd2c5e34035ac1e6c9b7e4723d881c5ceaa9

diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index 552110d..c5ce232 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -187,6 +187,15 @@ public:
     /** Reset with LanguageType MS-LangID. */
     void                            reset( LanguageType nLanguage );
 
+
+    /** Fall back to a known locale.
+
+        If the current tag does not represent a known (by us) locale, fall back
+        to the most likely locale possible known.
+        If the current tag is known, no change occurs.
+     */
+    LanguageTag &                   makeFallback();
+
 private:
 
     enum Decision
@@ -213,6 +222,7 @@ private:
     mutable bool                            mbCachedLanguage    : 1;
     mutable bool                            mbCachedScript      : 1;
     mutable bool                            mbCachedCountry     : 1;
+            bool                            mbIsFallback        : 1;
 
     void    convertLocaleToBcp47();
     void    convertLocaleToLang();
diff --git a/i18npool/inc/i18npool/mslangid.hxx b/i18npool/inc/i18npool/mslangid.hxx
index 574a07d..120d9c6 100644
--- a/i18npool/inc/i18npool/mslangid.hxx
+++ b/i18npool/inc/i18npool/mslangid.hxx
@@ -149,6 +149,14 @@ private:
             const ::com::sun::star::lang::Locale & rLocale );
 
 
+    /** To be used only by LanguageTag. */
+    I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
+
+    /** To be used only by LanguageTag. */
+    I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
+            const ::com::sun::star::lang::Locale & rLocale );
+
+
 #if I18NPOOL_FORCE_LANGUAGETAG
 public:
 #endif
@@ -317,12 +325,9 @@ private:
     I18NISOLANG_DLLPRIVATE static inline LanguageType simplifySystemLanguages( LanguageType nLang );
 
     // Several locale lookups with fall-back
-    I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage( LanguageType nLang );
     I18NISOLANG_DLLPRIVATE static LanguageType lookupFallbackLanguage(
             const ::com::sun::star::lang::Locale & rLocale );
     I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale( LanguageType nLang );
-    I18NISOLANG_DLLPRIVATE static ::com::sun::star::lang::Locale lookupFallbackLocale(
-            const ::com::sun::star::lang::Locale & rLocale );
 };
 
 
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index f863ae2..1dcc6bf 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -162,7 +162,8 @@ LanguageTag::LanguageTag( const rtl::OUString & rBcp47LanguageTag, bool bCanonic
         mbInitializedLangID( false),
         mbCachedLanguage( false),
         mbCachedScript( false),
-        mbCachedCountry( false)
+        mbCachedCountry( false),
+        mbIsFallback( false)
 {
     theDataRef::get().incRef();
 
@@ -185,7 +186,8 @@ LanguageTag::LanguageTag( const com::sun::star::lang::Locale & rLocale )
         mbInitializedLangID( false),
         mbCachedLanguage( false),
         mbCachedScript( false),
-        mbCachedCountry( false)
+        mbCachedCountry( false),
+        mbIsFallback( false)
 {
     theDataRef::get().incRef();
 }
@@ -204,7 +206,8 @@ LanguageTag::LanguageTag( LanguageType nLanguage )
         mbInitializedLangID( !mbSystemLocale),
         mbCachedLanguage( false),
         mbCachedScript( false),
-        mbCachedCountry( false)
+        mbCachedCountry( false),
+        mbIsFallback( false)
 {
     theDataRef::get().incRef();
 }
@@ -224,7 +227,8 @@ LanguageTag::LanguageTag( const rtl::OUString& rLanguage, const rtl::OUString& r
         mbInitializedLangID( false),
         mbCachedLanguage( false),
         mbCachedScript( false),
-        mbCachedCountry( false)
+        mbCachedCountry( false),
+        mbIsFallback( false)
 {
     theDataRef::get().incRef();
 }
@@ -249,7 +253,8 @@ LanguageTag::LanguageTag( const LanguageTag & rLanguageTag )
         mbInitializedLangID( rLanguageTag.mbInitializedLangID),
         mbCachedLanguage( rLanguageTag.mbCachedLanguage),
         mbCachedScript( rLanguageTag.mbCachedScript),
-        mbCachedCountry( rLanguageTag.mbCachedCountry)
+        mbCachedCountry( rLanguageTag.mbCachedCountry),
+        mbIsFallback( rLanguageTag.mbIsFallback)
 {
     theDataRef::get().incRef();
 }
@@ -276,6 +281,7 @@ LanguageTag& LanguageTag::operator=( const LanguageTag & rLanguageTag )
     mbCachedLanguage    = rLanguageTag.mbCachedLanguage;
     mbCachedScript      = rLanguageTag.mbCachedScript;
     mbCachedCountry     = rLanguageTag.mbCachedCountry;
+    mbIsFallback        = rLanguageTag.mbIsFallback;
     return *this;
 }
 
@@ -313,6 +319,7 @@ void LanguageTag::resetVars()
     mbCachedLanguage    = false;
     mbCachedScript      = false;
     mbCachedCountry     = false;
+    mbIsFallback        = false;
 }
 
 
@@ -806,4 +813,30 @@ bool LanguageTag::isSystemLocale() const
 }
 
 
+LanguageTag & LanguageTag::makeFallback()
+{
+    if (!mbIsFallback)
+    {
+        if (mbInitializedLangID)
+        {
+            LanguageType nLang1 = getLanguageType();
+            LanguageType nLang2 = MsLangId::lookupFallbackLanguage( nLang1);
+            if (nLang1 != nLang2)
+                reset( nLang2);
+        }
+        else
+        {
+            const lang::Locale& rLocale1 = getLocale();
+            lang::Locale aLocale2( MsLangId::lookupFallbackLocale( rLocale1));
+            if (    rLocale1.Language != aLocale2.Language ||
+                    rLocale1.Country  != aLocale2.Country ||
+                    rLocale1.Variant  != aLocale2.Variant)
+                reset( aLocale2);
+        }
+        mbIsFallback = true;
+    }
+    return *this;
+}
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list