Bug 1313950 - properly localize plurals of number of matches in Addressbook search. r=IanN,mkmelin a=IanN a=jorgk(Aurora)
authoraceman <acelists@atlas.sk>
Fri, 04 Nov 2016 11:12:00 +0100
changeset 23671 5082b3870a86205345bb8a2d23456602dad7e7b7
parent 23670 ab1eb5ee1f6903a9045eb021ed1e87d0bca0e090
child 23672 e4048c5210628c6cf2942d6f3323e0069568f3d3
push id1927
push usermozilla@jorgk.com
push dateMon, 05 Dec 2016 10:22:52 +0000
treeherdercomm-aurora@a463541c0347 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, mkmelin, IanN, jorgk
bugs1313950
Bug 1313950 - properly localize plurals of number of matches in Addressbook search. r=IanN,mkmelin a=IanN a=jorgk(Aurora)
mail/base/content/ABSearchDialog.js
mail/components/addrbook/content/addressbook.js
mail/locales/en-US/chrome/messenger/addressbook/addressBook.properties
suite/locales/en-US/chrome/mailnews/addressbook/addressBook.properties
suite/mailnews/addrbook/addressbook.js
suite/mailnews/search/ABSearchDialog.js
--- a/mail/base/content/ABSearchDialog.js
+++ b/mail/base/content/ABSearchDialog.js
@@ -1,14 +1,15 @@
 /* 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/. */
 
 Components.utils.import("resource:///modules/ABQueryUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/PluralForm.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
 var gSearchSession;
 
 var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope;
 var nsIMsgSearchTerm = Components.interfaces.nsIMsgSearchTerm;
 var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp;
@@ -24,29 +25,26 @@ var gPropertiesCmd;
 var gComposeCmd;
 var gDeleteCmd;
 var gSearchPhoneticName = "false";
 
 var gSearchAbViewListener = {
   onSelectionChanged: function() {
     UpdateCardView();
   },
-  onCountChanged: function(total) {
-    var statusText;
-    switch (total) {
-      case 0:
-        statusText = gAddressBookBundle.getString("noMatchFound");
-        break;
-      case 1:
-        statusText = gAddressBookBundle.getString("matchFound");
-        break;
-      default:
-        statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
-        break;
+  onCountChanged: function(aTotal) {
+    let statusText;
+    if (aTotal == 0) {
+      statusText = gAddressBookBundle.getString("noMatchFound");
+    } else {
+      statusText = PluralForm
+        .get(aTotal, gAddressBookBundle.getString("matchesFoundCount"))
+        .replace("%S", aTotal);
     }
+
     gStatusText.setAttribute("label", statusText);
   }
 };
 
 function searchOnLoad()
 {
   initializeSearchWidgets();
   initializeSearchWindowWidgets();
--- a/mail/components/addrbook/content/addressbook.js
+++ b/mail/components/addrbook/content/addressbook.js
@@ -1,20 +1,21 @@
 /* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /*
  * 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/. */
 
-Components.utils.import("resource://gre/modules/Services.jsm");
 // Ensure the activity modules are loaded for this window.
 Components.utils.import("resource:///modules/activity/activityModules.js");
 Components.utils.import("resource:///modules/ABQueryUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/PluralForm.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 var nsIAbListener = Components.interfaces.nsIAbListener;
 var kPrefMailAddrBookLastNameFirst = "mail.addr_book.lastnamefirst";
 var kPersistCollapseMapStorage = "directoryTree.json";
 
 var gSearchTimer = null;
 var gStatusText = null;
 var gQueryURIFormat = null;
@@ -483,24 +484,22 @@ function SetStatusText(total)
   if (!gStatusText)
     gStatusText = document.getElementById('statusText');
 
   try {
     var statusText;
 
     var searchInput = document.getElementById("peopleSearchInput");
     if (searchInput && searchInput.value) {
-      if (total == 0)
+      if (total == 0) {
         statusText = gAddressBookBundle.getString("noMatchFound");
-      else
-      {
-        if (total == 1)
-          statusText = gAddressBookBundle.getString("matchFound");
-        else
-          statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
+      } else {
+        statusText = PluralForm
+          .get(total, gAddressBookBundle.getString("matchesFoundCount"))
+          .replace("%S", total);
       }
     }
     else
       statusText =
         gAddressBookBundle.getFormattedString(
           "totalContactStatus",
           [GetDirectoryFromURI(GetSelectedDirectory()).dirName, total]);
 
--- a/mail/locales/en-US/chrome/messenger/addressbook/addressBook.properties
+++ b/mail/locales/en-US/chrome/messenger/addressbook/addressBook.properties
@@ -104,20 +104,20 @@ ldap_2.servers.pab.description=Personal 
 ldap_2.servers.history.description=Collected Addresses
 ## LOCALIZATION NOTE (ldap_2.servers.osx.description is only used on Mac OS X)
 ldap_2.servers.osx.description=Mac OS X Address Book
 
 # status bar stuff
 ## LOCALIZATION NOTE (totalContactStatus):
 ## %1$S is address book name, %2$S is contact count
 totalContactStatus=Total contacts in %1$S: %2$S
-## LOCALIZATION NOTE (matchesFound):  do not localize %S
 noMatchFound=No matches found
-matchFound=1 match found
-matchesFound=%S matches found
+# LOCALIZATION NOTE (matchesFoundCount): Semi-colon list of plural forms
+# $S is the number of matches found
+matchesFoundCount=%S match found;%S matches found
 
 ## LOCALIZATION NOTE (contactsCopied): Semi-colon list of plural forms
 ## %1$S is the number of contacts that were copied. This should be used multiple
 ## times wherever you need it. Do not replace by %S.
 contactsCopied=%1$S contact copied;%1$S contacts copied
 
 ## LOCALIZATION NOTE (contactsMoved): Semi-colon list of plural forms
 ## %1$S is the number of contacts that were moved. This should be used multiple
--- a/suite/locales/en-US/chrome/mailnews/addressbook/addressBook.properties
+++ b/suite/locales/en-US/chrome/mailnews/addressbook/addressBook.properties
@@ -97,20 +97,20 @@ ldap_2.servers.history.description=Colle
 ldap_2.servers.oe.description=OE Contacts
 ## LOCALIZATION NOTE (ldap_2.servers.osx.description is only used on Mac OS X)
 ldap_2.servers.osx.description=Mac OS X Address Book
 
 # status bar stuff
 ## LOCALIZATION NOTE (totalContactStatus): 
 ## %1$S is address book name, %2$S is card count
 totalContactStatus=Total contacts in %1$S: %2$S
-## LOCALIZATION NOTE (matchesFound):  do not localize %S
 noMatchFound=No matches found
-matchFound=1 match found
-matchesFound=%S matches found
+# LOCALIZATION NOTE (matchesFoundCount): Semi-colon list of plural forms
+# $S is the number of matches found
+matchesFoundCount=%S match found;%S matches found
 
 ## LOCALIZATION NOTE (contactsCopied): Semi-colon list of plural forms
 ## %1$S is the number of contacts that were copied. This should be used multiple
 ## times wherever you need it. Do not replace by %S.
 contactsCopied=%1$S contact copied;%1$S contacts copied
 
 ## LOCALIZATION NOTE (contactsMoved): Semi-colon list of plural forms
 ## %1$S is the number of contacts that were moved. This should be used multiple
--- a/suite/mailnews/addrbook/addressbook.js
+++ b/suite/mailnews/addrbook/addressbook.js
@@ -1,13 +1,16 @@
 /* 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/. */
 
 Components.utils.import("resource:///modules/ABQueryUtils.jsm");
+Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/PluralForm.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 const nsIAbListener = Components.interfaces.nsIAbListener;
 const kPrefMailAddrBookLastNameFirst = "mail.addr_book.lastnamefirst";
 const kPersistCollapseMapStorage = "directoryTree.json";
 
 var gSearchTimer = null;
 var gStatusText = null;
 var gQueryURIFormat = null;
@@ -341,24 +344,22 @@ function SetStatusText(total)
 {
   if (!gStatusText)
     gStatusText = document.getElementById('statusText');
 
   try {
     var statusText;
 
     if (gSearchInput.value) {
-      if (total == 0)
+      if (total == 0) {
         statusText = gAddressBookBundle.getString("noMatchFound");
-      else
-      {
-        if (total == 1)
-          statusText = gAddressBookBundle.getString("matchFound");
-        else
-          statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
+      } else {
+        statusText = PluralForm
+          .get(total, gAddressBookBundle.getString("matchesFoundCount"))
+          .replace("%S", total);
       }
     }
     else
       statusText = gAddressBookBundle.getFormattedString("totalContactStatus", [gAbView.directory.dirName, total]);
 
     gStatusText.setAttribute("label", statusText);
   }
   catch(ex) {
--- a/suite/mailnews/search/ABSearchDialog.js
+++ b/suite/mailnews/search/ABSearchDialog.js
@@ -1,14 +1,15 @@
 /* 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/. */
 
 Components.utils.import("resource:///modules/ABQueryUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/PluralForm.jsm");
 
 var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
 var gSearchSession;
 
 var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope;
 var nsIMsgSearchTerm = Components.interfaces.nsIMsgSearchTerm;
 var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp;
 var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib;
@@ -22,29 +23,26 @@ var gSearchStopButton;
 var gPropertiesButton;
 var gComposeButton;
 var gSearchPhoneticName = "false";
 
 var gSearchAbViewListener = {
   onSelectionChanged: function() {
     UpdateCardView();
   },
-  onCountChanged: function(total) {
-    var statusText;
-    switch (total) {
-      case 0:
-        statusText = gAddressBookBundle.getString("noMatchFound");
-        break;
-      case 1:
-        statusText = gAddressBookBundle.getString("matchFound");
-        break;
-      default:
-        statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
-        break;
+  onCountChanged: function(aTotal) {
+    let statusText;
+    if (aTotal == 0) {
+      statusText = gAddressBookBundle.getString("noMatchFound");
+    } else {
+      statusText = PluralForm
+        .get(aTotal, gAddressBookBundle.getString("matchesFoundCount"))
+        .replace("%S", aTotal);
     }
+
     gStatusText.setAttribute("label", statusText);
   }
 };
 
 function searchOnLoad()
 {
   setHelpFileURI("chrome://communicator/locale/help/suitehelp.rdf");
   UpgradeAddressBookResultsPaneUI("mailnews.ui.advanced_directory_search_results.version");