summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-04-24 22:55:43 +0200
committerEike Rathke <erack@redhat.com>2013-04-24 23:10:31 +0200
commit095f3dde425eb79da0e7fbfe40e18de1ac4f368b (patch)
treefc22271125013d978fe77effe3c790fcdf51cb6c
parent6681432e39228deb982105caa8de2319c2084a08 (diff)
introduced libi18nlangtagicu
Change-Id: Ie80e989d55d465e127ccc20290d654acf222e5bb
-rw-r--r--Library_merged.mk1
-rw-r--r--Repository.mk1
-rw-r--r--RepositoryModule_host.mk1
-rw-r--r--i18nlangtag/Library_i18nlangtagicu.mk32
-rw-r--r--i18nlangtag/Module_i18nlangtag.mk1
-rw-r--r--i18nlangtag/source/languagetag/languagetagicu.cxx36
-rw-r--r--include/i18nlangtag/languagetag.hxx1
-rw-r--r--include/i18nlangtag/languagetagicu.hxx44
8 files changed, 117 insertions, 0 deletions
diff --git a/Library_merged.mk b/Library_merged.mk
index 2d5ef603de57..4603bda34aad 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 054d9a325871..c4858b73eab0 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 1b939f139214..e504cdcd15f9 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 000000000000..d1def1b37339
--- /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 edd2e1d2e2a9..22b8a7f42de9 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 000000000000..6f426d6a67c8
--- /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 e5ba011ab2ba..15ca4ec8bbc5 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 000000000000..20e5349f7875
--- /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: */