[Libreoffice-commits] core.git: 2 commits - i18nlangtag/Library_i18nlangtagicu.mk i18nlangtag/Module_i18nlangtag.mk i18nlangtag/source include/i18nlangtag Library_merged.mk lotuswordpro/Library_lwpft.mk lotuswordpro/source Repository.mk RepositoryModule_host.mk

Eike Rathke erack at redhat.com
Wed Apr 24 14:10:52 PDT 2013


 Library_merged.mk                                 |    1 
 Repository.mk                                     |    1 
 RepositoryModule_host.mk                          |    1 
 i18nlangtag/Library_i18nlangtagicu.mk             |   32 ++++++++++++++++
 i18nlangtag/Module_i18nlangtag.mk                 |    1 
 i18nlangtag/source/languagetag/languagetagicu.cxx |   36 ++++++++++++++++++
 include/i18nlangtag/languagetag.hxx               |    1 
 include/i18nlangtag/languagetagicu.hxx            |   44 ++++++++++++++++++++++
 lotuswordpro/Library_lwpft.mk                     |    1 
 lotuswordpro/source/filter/lwptools.cxx           |   21 +++-------
 10 files changed, 124 insertions(+), 15 deletions(-)

New commits:
commit 56e753aa6a762337ec09bd30445ad4b75c3bf5fe
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Apr 24 23:07:13 2013 +0200

    use LanguageTagIcu
    
    Change-Id: I048d72c0cd633e3aa9e6a74e4f111703969b1d77

diff --git a/lotuswordpro/Library_lwpft.mk b/lotuswordpro/Library_lwpft.mk
index f01261d..7673eb3 100644
--- a/lotuswordpro/Library_lwpft.mk
+++ b/lotuswordpro/Library_lwpft.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_Library_use_libraries,lwpft,\
     cppuhelper \
     sal \
 	i18nlangtag \
+	i18nlangtagicu \
     sfx \
     sot \
     svt \
diff --git a/lotuswordpro/source/filter/lwptools.cxx b/lotuswordpro/source/filter/lwptools.cxx
index dd723cc..9ef4ec5 100644
--- a/lotuswordpro/source/filter/lwptools.cxx
+++ b/lotuswordpro/source/filter/lwptools.cxx
@@ -71,6 +71,7 @@
 #include <vcl/settings.hxx>
 #include <unicode/datefmt.h>
 #include <unicode/udat.h>
+#include <i18nlangtag/languagetagicu.hxx>
 
 #ifdef SAL_UNX
 #define SEPARATOR '/'
@@ -284,15 +285,10 @@ XFDateStyle* LwpTools::GetSystemDateStyle(sal_Bool bLongFormat)
         udat_toPattern(fmt,true,pattern,nLength,&status);
     }
 */
-    /* FIXME-BCP47: handle language tags! */
     //1 get locale for system
-    ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLanguageTag().getLocale();
-    OUString strLang = aLocale.Language;
-    OUString strCountry = aLocale.Country;
-    icu::Locale bLocale((char*)(OUStringToOString(strLang,RTL_TEXTENCODING_MS_1252).getStr()),
-        (char*)(OUStringToOString(strCountry,RTL_TEXTENCODING_MS_1252).getStr()));
+    icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
     //2 get icu format pattern by locale
-    icu::DateFormat* fmt = icu::DateFormat::createDateInstance(style,bLocale);
+    icu::DateFormat* fmt = icu::DateFormat::createDateInstance(style,aLocale);
 
     int32_t nLength = 0;
     int32_t nLengthNeed;
@@ -698,16 +694,11 @@ XFTimeStyle* LwpTools::GetSystemTimeStyle()
         udat_toPattern(fmt,true,pattern,nLength,&status);
     }
 */
-    /* FIXME-BCP47: handle language tags! */
     //1 get locale for system
-    ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLanguageTag().getLocale();
-    OUString strLang = aLocale.Language;
-    OUString strCountry = aLocale.Country;
-    icu::Locale bLocale((char*)(OUStringToOString(strLang,RTL_TEXTENCODING_MS_1252).getStr()),
-        (char*)(OUStringToOString(strCountry,RTL_TEXTENCODING_MS_1252).getStr()));
-
-    icu::DateFormat* fmt = icu::DateFormat::createTimeInstance(icu::DateFormat::DEFAULT,bLocale);
+    icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
     //2 get icu format pattern by locale
+    icu::DateFormat* fmt = icu::DateFormat::createTimeInstance(icu::DateFormat::DEFAULT,aLocale);
+
     int32_t nLength = 0;
     int32_t nLengthNeed;
     UErrorCode status = U_ZERO_ERROR;
commit 095f3dde425eb79da0e7fbfe40e18de1ac4f368b
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Apr 24 22:55:43 2013 +0200

    introduced libi18nlangtagicu
    
    Change-Id: Ie80e989d55d465e127ccc20290d654acf222e5bb

diff --git a/Library_merged.mk b/Library_merged.mk
index 2d5ef60..4603bda 100644
--- a/Library_merged.mk
+++ b/Library_merged.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_Library_use_libraries,merged,\
 	cppu \
 	cppuhelper \
 	i18nlangtag \
+	i18nlangtagicu \
 	$(if $(filter TRUE,$(SOLAR_JAVA)), \
 		jvmaccess \
 		jvmfwk) \
diff --git a/Repository.mk b/Repository.mk
index 054d9a3..c4858b7 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -469,6 +469,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,OOO, \
 	deployment \
 	fileacc \
 	i18nlangtag \
+	i18nlangtagicu \
 	i18nutil \
 	mcnttype \
 	package2 \
diff --git a/RepositoryModule_host.mk b/RepositoryModule_host.mk
index 1b939f1..e504cdc 100644
--- a/RepositoryModule_host.mk
+++ b/RepositoryModule_host.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_Module_add_moduledirs,libreoffice,\
 	hwpfilter \
 	$(call gb_Helper_optional,HYPHEN,hyphen) \
 	i18nlangtag \
+	i18nlangtagicu \
 	i18npool \
 	i18nutil \
 	$(call gb_Helper_optional,ICU,icu) \
diff --git a/i18nlangtag/Library_i18nlangtagicu.mk b/i18nlangtag/Library_i18nlangtagicu.mk
new file mode 100644
index 0000000..d1def1b
--- /dev/null
+++ b/i18nlangtag/Library_i18nlangtagicu.mk
@@ -0,0 +1,32 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+$(eval $(call gb_Library_Library,i18nlangtagicu))
+
+$(eval $(call gb_Library_use_sdk_api,i18nlangtagicu))
+
+$(eval $(call gb_Library_add_defs,i18nlangtagicu,\
+	-DI18NLANGTAG_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Library_use_libraries,i18nlangtagicu,\
+	sal \
+	i18nlangtag \
+	$(gb_UWINAPI) \
+))
+
+$(eval $(call gb_Library_use_externals,i18nlangtagicu,\
+	icu_headers \
+	icuuc \
+))
+
+$(eval $(call gb_Library_add_exception_objects,i18nlangtagicu,\
+	i18nlangtag/source/languagetag/languagetagicu \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/i18nlangtag/Module_i18nlangtag.mk b/i18nlangtag/Module_i18nlangtag.mk
index edd2e1d..22b8a7f 100644
--- a/i18nlangtag/Module_i18nlangtag.mk
+++ b/i18nlangtag/Module_i18nlangtag.mk
@@ -10,6 +10,7 @@ $(eval $(call gb_Module_Module,i18nlangtag))
 
 $(eval $(call gb_Module_add_targets,i18nlangtag,\
 	Library_i18nlangtag \
+	Library_i18nlangtagicu \
 ))
 
 $(eval $(call gb_Module_add_check_targets,i18nlangtag,\
diff --git a/i18nlangtag/source/languagetag/languagetagicu.cxx b/i18nlangtag/source/languagetag/languagetagicu.cxx
new file mode 100644
index 0000000..6f426d6
--- /dev/null
+++ b/i18nlangtag/source/languagetag/languagetagicu.cxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "i18nlangtag/languagetagicu.hxx"
+#include "i18nlangtag/languagetag.hxx"
+
+
+// static
+icu::Locale LanguageTagIcu::getIcuLocale( const LanguageTag & rLanguageTag )
+{
+    if (rLanguageTag.isIsoLocale())
+    {
+        // The simple case.
+        const com::sun::star::lang::Locale& rLocale = rLanguageTag.getLocale();
+        if (rLocale.Country.isEmpty())
+            return icu::Locale( OUStringToOString( rLocale.Language, RTL_TEXTENCODING_ASCII_US).getStr());
+        return icu::Locale(
+                OUStringToOString( rLocale.Language, RTL_TEXTENCODING_ASCII_US).getStr(),
+                OUStringToOString( rLocale.Country, RTL_TEXTENCODING_ASCII_US).getStr());
+    }
+
+    /* TODO: could we optimize this for the isIsoODF() case where only a script
+     * is added? */
+
+    // Let ICU decide how it wants a BCP47 string stuffed into its Locale.
+    return icu::Locale::createFromName(
+            OUStringToOString( rLanguageTag.getBcp47(), RTL_TEXTENCODING_ASCII_US).getStr());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index e5ba011..15ca4ec 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -393,6 +393,7 @@ private:
                                        OUString& rLanguage,
                                        OUString& rScript,
                                        OUString& rCountry );
+
 };
 
 #endif  // INCLUDED_I18NLANGTAG_LANGUAGETAG_HXX
diff --git a/include/i18nlangtag/languagetagicu.hxx b/include/i18nlangtag/languagetagicu.hxx
new file mode 100644
index 0000000..20e5349
--- /dev/null
+++ b/include/i18nlangtag/languagetagicu.hxx
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_I18NLANGTAG_LANGUAGETAGICU_HXX
+#define INCLUDED_I18NLANGTAG_LANGUAGETAGICU_HXX
+
+#include <sal/config.h>
+#include <i18nlangtag/i18nlangtagdllapi.h>
+#include <unicode/locid.h>
+
+class LanguageTag;
+
+
+/** Interface LanguageTag to ICU's icu::Locale
+
+    Separated from LanguageTag into its own library to not pollute the entire
+    code base with ICU header file inclusion and linkage, only the few code
+    actually using this needs to link against ICU libraries, which it did
+    anyway.
+*/
+class I18NLANGTAG_DLLPUBLIC LanguageTagIcu
+{
+public:
+
+    /** Obtain language tag as ICU icu::Locale.
+
+        If the language tag is a "pure" ISO locale (see
+        LanguageTag::getLocale()) that is directly constructed, otherwise it is
+        converted using the available ICU mechanisms.
+
+        Always resolves an empty tag to the system locale.
+     */
+    static  icu::Locale     getIcuLocale( const LanguageTag & rLanguageTag );
+};
+
+#endif  // INCLUDED_I18NLANGTAG_LANGUAGETAGICU_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list