[Libreoffice-commits] core.git: 2 commits - cui/Library_cui.mk cui/source i18nutil/Library_i18nutil.mk i18nutil/source include/i18nutil

Caolán McNamara caolanm at redhat.com
Mon Jan 20 03:19:45 PST 2014


 cui/Library_cui.mk                  |    1 +
 cui/source/tabpages/autocdlg.cxx    |    7 +++++--
 i18nutil/Library_i18nutil.mk        |    3 +++
 i18nutil/source/utility/unicode.cxx |   26 ++++++++++++++++++++++++++
 include/i18nutil/unicode.hxx        |    7 +++++++
 5 files changed, 42 insertions(+), 2 deletions(-)

New commits:
commit 4706cecf542b08c6af24bdddf61ccf912f515e13
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Jan 20 11:18:11 2014 +0000

    Related: #i56998# use locale rules to format percentage...
    
    in Combine single line paragraphs option in AutoCorrect dialog
    
    Change-Id: I5af78ff31031a92a4f772d9c26bee05c3695cad1

diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index 19d2345..cc80cf4 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_Library_use_libraries,cui,\
     drawinglayer \
     editeng \
     i18nlangtag \
+    i18nutil \
     $(if $(ENABLE_JAVA), \
         jvmfwk) \
     lng \
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index 0fb4c17..67a2181 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <i18nutil/unicode.hxx>
 #include <vcl/builder.hxx>
 #include <vcl/msgbox.hxx>
 #include <vcl/field.hxx>
@@ -659,7 +660,8 @@ void OfaSwAutoFmtOptionsPage::Reset( const SfxItemSet& )
     m_pCheckLB->SetUserData(  REPLACE_BULLETS, pUserData );
 
     nPercent = pOpt->nRightMargin;
-    sMargin = " " + OUString::number( nPercent ) + "%";
+    sMargin = " " +
+        unicode::formatPercent(nPercent, Application::GetSettings().GetUILanguageTag());
     pUserData = new ImpUserData(&sMargin, 0);
     m_pCheckLB->SetUserData( MERGE_SINGLE_LINE_PARA, pUserData );
 
@@ -713,7 +715,8 @@ IMPL_LINK_NOARG(OfaSwAutoFmtOptionsPage, EditHdl)
         if(RET_OK == aDlg.Execute())
         {
             nPercent = (sal_uInt16)aDlg.GetPrcntFld().GetValue();
-            sMargin = " " + OUString::number( nPercent ) + "%";
+            sMargin = " " +
+                unicode::formatPercent(nPercent, Application::GetSettings().GetUILanguageTag());
         }
     }
     m_pCheckLB->Invalidate();
commit c2866a9da4822fe886683efabe223db97d0296cb
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Jan 20 10:41:32 2014 +0000

    Related: #i56998# provide a way to format % per-locale rules
    
    Change-Id: Ic27b230cc9dce366f281ff720ded5873e94f6191

diff --git a/i18nutil/Library_i18nutil.mk b/i18nutil/Library_i18nutil.mk
index 8c0aaf0..1c5837c 100644
--- a/i18nutil/Library_i18nutil.mk
+++ b/i18nutil/Library_i18nutil.mk
@@ -21,6 +21,8 @@ $(eval $(call gb_Library_Library,i18nutil))
 $(eval $(call gb_Library_use_externals,i18nutil,\
 	boost_headers \
 	icu_headers \
+	icui18n \
+	icuuc \
 ))
 
 $(eval $(call gb_Library_use_custom_headers,i18nutil,\
@@ -34,6 +36,7 @@ $(eval $(call gb_Library_add_defs,i18nutil,\
 ))
 
 $(eval $(call gb_Library_use_libraries,i18nutil,\
+	i18nlangtag \
 	comphelper \
 	cppu \
 	sal \
diff --git a/i18nutil/source/utility/unicode.cxx b/i18nutil/source/utility/unicode.cxx
index 0098969..56daacd 100644
--- a/i18nutil/source/utility/unicode.cxx
+++ b/i18nutil/source/utility/unicode.cxx
@@ -17,10 +17,14 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <boost/scoped_ptr.hpp>
 #include <com/sun/star/i18n/UnicodeType.hpp>
 #include <com/sun/star/i18n/KCharacterType.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
+#include <i18nlangtag/languagetag.hxx>
+#include <i18nlangtag/languagetagicu.hxx>
 #include <i18nutil/unicode.hxx>
+#include <unicode/numfmt.h>
 #include "unicode_data.h"
 
 // Workaround for glibc braindamage:
@@ -934,4 +938,26 @@ OString SAL_CALL unicode::getExemplarLanguageForUScriptCode(UScriptCode eScript)
     return sRet;
 }
 
+//Format a number as a percentage according to the rules of the given
+//language, e.g. 100 -> "100%" for en-US vs "100 %" for de-DE
+OUString SAL_CALL unicode::formatPercent(double dNumber,
+    const LanguageTag &rLangTag)
+{
+    // get a currency formatter for this locale ID
+    UErrorCode errorCode=U_ZERO_ERROR;
+    icu::Locale aLocale = LanguageTagIcu::getIcuLocale(rLangTag);
+    boost::scoped_ptr<NumberFormat> xF(
+        NumberFormat::createPercentInstance(aLocale, errorCode));
+    if(U_FAILURE(errorCode))
+    {
+        SAL_WARN("i18n", "NumberFormat::createPercentInstance failed");
+        return OUString::number(dNumber) + "%";
+    }
+
+    UnicodeString output;
+    xF->format(dNumber, output);
+    return OUString(reinterpret_cast<const sal_Unicode *>(output.getBuffer()),
+        output.length());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/i18nutil/unicode.hxx b/include/i18nutil/unicode.hxx
index ae1ad06..e321039 100644
--- a/include/i18nutil/unicode.hxx
+++ b/include/i18nutil/unicode.hxx
@@ -24,6 +24,8 @@
 #include <unicode/uscript.h>
 #include <i18nutil/i18nutildllapi.h>
 
+class LanguageTag;
+
 typedef struct _ScriptTypeList {
     sal_Int16 from;
     sal_Int16 to;
@@ -54,6 +56,11 @@ public:
 
     //Return a language that can be written in a given ISO 15924 script code
     static OString SAL_CALL getExemplarLanguageForUScriptCode(UScriptCode eScript);
+
+    //Format a number as a percentage according to the rules of the given
+    //language, e.g. 100 -> "100%" for en-US vs "100 %" for de-DE
+    static OUString SAL_CALL formatPercent(double dNumber,
+        const LanguageTag &rLangTag);
 };
 
 #endif


More information about the Libreoffice-commits mailing list