Bug 668756 - Allow localizing of the decimal separator used in message/file size display. r=mbanner
authoraceman <acelists@atlas.sk>
Tue, 09 Oct 2012 20:37:15 -0400
changeset 14014 f993893786c0f2509264b48630ed00be28c34333
parent 14013 cd3a38d7b2b919b2b4f4db40503a8af01ab5704b
child 14015 de7b9f15cd2ed1f4d2c455ab737773bfff99b96e
push id804
push userbugzilla@standard8.plus.com
push dateMon, 07 Jan 2013 21:31:35 +0000
treeherdercomm-beta@9fdc5c67cdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbanner
bugs668756
Bug 668756 - Allow localizing of the decimal separator used in message/file size display. r=mbanner
configure.in
mailnews/base/util/nsMsgUtils.cpp
--- a/configure.in
+++ b/configure.in
@@ -3752,16 +3752,18 @@ AC_CACHE_CHECK(for LC_MESSAGES,
 		ac_cv_i18n_lc_messages,
 		[AC_TRY_COMPILE([#include <locale.h>],
 				[int category = LC_MESSAGES;],
 				ac_cv_i18n_lc_messages=yes,
 				ac_cv_i18n_lc_messages=no)])
 if test "$ac_cv_i18n_lc_messages" = yes; then
    AC_DEFINE(HAVE_I18N_LC_MESSAGES)
 fi
+
+AC_HAVE_FUNCS(localeconv)
 fi # ! SKIP_COMPILER_CHECKS
 
 TARGET_XPCOM_ABI=
 if test -n "${CPU_ARCH}" -a -n "${TARGET_COMPILER_ABI}"; then
     TARGET_XPCOM_ABI="${CPU_ARCH}-${TARGET_COMPILER_ABI}"
 fi
 
 dnl Mozilla specific options
@@ -3797,16 +3799,17 @@ fi
 
 dnl We can't run TRY_COMPILE tests on Windows, so hard-code some
 dnl features that Windows actually does support.
 
 if test -n "$SKIP_COMPILER_CHECKS"; then
    dnl Windows has malloc.h
    AC_DEFINE(MALLOC_H, [<malloc.h>])
    AC_DEFINE(HAVE_FORCEINLINE)
+   AC_DEFINE(HAVE_LOCALECONV)
 fi # SKIP_COMPILER_CHECKS
 
 
 dnl ========================================================
 dnl =
 dnl = Check for external package dependencies
 dnl =
 dnl ========================================================
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -66,16 +66,17 @@
 #include "nsICharsetDetector.h"
 #include "nsILineInputStream.h"
 #include "nsIPlatformCharset.h"
 #include "nsIParserUtils.h"
 #include "nsICharsetConverterManager.h"
 #include "nsIDocumentEncoder.h"
 #include "mozilla/Services.h"
 #include "mozilla/Util.h"
+#include "locale.h"
 using namespace mozilla;
 
 static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
 static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID);
 static NS_DEFINE_CID(kCNntpUrlCID, NS_NNTPURL_CID);
 
 #define ILLEGAL_FOLDER_CHARS ";#"
 #define ILLEGAL_FOLDER_CHARS_AS_FIRST_LETTER "."
@@ -517,16 +518,36 @@ nsresult FormatFileSize(uint64_t size, b
                                  getter_Copies(sizeAbbr));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get rid of insignificant bits by truncating to 1 or 0 decimal points
   // 0.1 -> 0.1; 1.2 -> 1.2; 12.3 -> 12.3; 123.4 -> 123; 234.5 -> 235
   nsTextFormatter::ssprintf(
     formattedSize, sizeAbbr.get(),
     (unitIndex != 0) && (unitSize < 99.95 && unitSize != 0) ? 1 : 0, unitSize);
+
+  PRInt32 separatorPos = formattedSize.FindChar('.');
+  if (separatorPos != kNotFound) {
+    // The ssprintf returned a decimal number using a dot (.) as the decimal
+    // separator. Now we try to localize the separator.
+    // Try to get the decimal separator from the system's locale.
+    char *decimalPoint;
+#ifdef HAVE_LOCALECONV
+    struct lconv *locale = localeconv();
+    decimalPoint = locale->decimal_point;
+#else
+    decimalPoint = getenv("LOCALE_DECIMAL_POINT");
+#endif
+    NS_ConvertUTF8toUTF16 decimalSeparator(decimalPoint);
+    if (decimalSeparator.IsEmpty())
+      decimalSeparator.AssignLiteral(".");
+
+    formattedSize.Replace(separatorPos, 1, decimalSeparator);
+  }
+
   return NS_OK;
 }
 
 
 nsresult NS_MsgCreatePathStringFromFolderURI(const char *aFolderURI,
                                              nsCString& aPathCString,
                                              const nsCString &aScheme,
                                              bool aIsNewsFolder)