[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 4/4] Use gettext.ldngettext when necessary (#467603)



The i18n people have suggested using ngettext when we need to have
singular and plural forms of strings, where the count will vary as to
what we are reporting to the user.

I've made the changes they have suggested.  I created a new lambda
function called P_() to use for the plural cases.  P_() takes in three
parameters:

    1) The singular form of the string.
    2) The plural form of the string.
    3) A count.

Here's an example:

    ....some loop runs doing stuff
    bytesWritten = 47
    msg = P_("Wrote %d byte.",
             "Wrote %d bytes.",
             bytesWritten) % (bytesWritten,)
    print msg

The % substitution is correct at the end because P_() returns a single
string, so we only need the format string to account for that.

Some strings have been changed slightly to make it easier for
translations to other languages, particularly when choosing plural forms.
---
 iw/lvm_dialog_gui.py |   17 +++++++++++------
 iw/partition_gui.py  |   21 ++++++++++++---------
 po/Makefile          |    4 ++--
 storage/__init__.py  |    2 +-
 text.py              |    9 +++++++--
 vnc.py               |    5 ++++-
 yuminstall.py        |   12 ++++++------
 7 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/iw/lvm_dialog_gui.py b/iw/lvm_dialog_gui.py
index 733b776..18e140a 100644
--- a/iw/lvm_dialog_gui.py
+++ b/iw/lvm_dialog_gui.py
@@ -34,6 +34,7 @@ from storage.deviceaction import *
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
+P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
 
 import logging
 log = logging.getLogger("anaconda")
@@ -764,12 +765,16 @@ class VolumeGroupEditor:
 	self.editLogicalVolume(lv)
 
     def addLogicalVolumeCB(self, widget):
-	if self.numAvailableLVSlots() < 1:
-	    self.intf.messageWindow(_("No free slots"),
-				    _("You cannot create more than %s logical "
-				    "volumes per volume group.") % (lvm.MAX_LV_SLOTS,), custom_icon="error")
-	    return
-	
+        if self.numAvailableLVSlots() < 1:
+            self.intf.messageWindow(_("No free slots"),
+                P_("You cannot create more than %d logical volume "
+                   "per volume group.",
+                   "You cannot create more than %d logical volumes "
+                   "per volume group.", lvm.MAX_LV_SLOTS)
+                % (lvm.MAX_LV_SLOTS,),
+                custom_icon="error")
+            return
+
         (total, used, free) = self.computeSpaceValues()
 	if free <= 0:
 	    self.intf.messageWindow(_("No free space"),
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index 8215dc4..e75d6c6 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -1216,15 +1216,18 @@ class PartitionWindow(InstallWindow):
         maintable.set_col_spacings(5)
         row = 0
 
-	lbltxt = _("Software RAID allows you to combine "
-		   "several disks into a larger "
-		   "RAID device.  A RAID device can be configured to "
-		   "provide additional speed and "
-		   "reliability compared to using an individual drive.  "
-		   "For more information on using RAID devices "
-		   "please consult the %s documentation.\n\n"
-		   "You currently have %s software RAID "
-		   "partition(s) free to use.\n\n") % (productName, len(availraidparts))
+	numparts = P_("You currently have %d software RAID partition free to use.",
+		    "You currently have %d software RAID partitions free to use.",
+		    len(availraidparts))
+
+	lbltxt = _("Software RAID allows you to combine several disks into "
+		    "a larger RAID device.  A RAID device can be configured "
+		    "to provide additional speed and reliability compared "
+		    "to using an individual drive.  For more information on "
+		    "using RAID devices please consult the %s "
+		    "documentation.") % (productName,)
+
+	lbltxt = lbltxt + "\n\n" + numparts + "\n\n"
 
         if len(availraidparts) < 2:
 	    lbltxt = lbltxt + _("To use RAID you must first "
diff --git a/po/Makefile b/po/Makefile
index 6e5b1d2..b33aee7 100644
--- a/po/Makefile
+++ b/po/Makefile
@@ -28,9 +28,9 @@ all: $(FMTCATALOGS)
 
 $(NLSPACKAGE).pot: $(POTFILES) $(NONPOTFILES) intltool-po
 	xgettext --from-code=UTF-8 --default-domain=$(NLSPACKAGE) \
-		 --keyword=_ --keyword=N_ --lang=python $(PYPOTFILES)
+		 --keyword=_ --keyword=N_ --keyword=P_:1,2 --lang=python $(PYPOTFILES)
 	xgettext --from-code=UTF-8 --default-domain=$(NLSPACKAGE) -j \
-		 --keyword=_ --keyword=N_ --lang=c $(CPOTFILES) tmp/*.h
+		 --keyword=_ --keyword=N_ --keyword=P_:1,2 --lang=c $(CPOTFILES) tmp/*.h
 	cat ../lang-table | cut -f1 | while read line; do echo -e "\n#. generated from lang-table\nmsgid \"$$line\"\nmsgstr \"\""; done >> $(NLSPACKAGE).po
 	if cmp -s $(NLSPACKAGE).po $(NLSPACKAGE).pot; then \
 	    rm -f $(NLSPACKAGE).po; \
diff --git a/storage/__init__.py b/storage/__init__.py
index ab636b9..e87db9b 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -827,7 +827,7 @@ class Storage(object):
         if (root and
             root.size < self.anaconda.backend.getMinimumSizeMB("/")):
             errors.append(_("Your / partition is less than %s "
-                            "megabytes which is lower than recommended "
+                            "MB which is lower than recommended "
                             "for a normal %s install.")
                           %(self.anaconda.backend.getMinimumSizeMB("/"),
                             productName))
diff --git a/text.py b/text.py
index 70a5331..3d1c63d 100644
--- a/text.py
+++ b/text.py
@@ -40,6 +40,7 @@ import imputil
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
+P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
 
 import logging
 log = logging.getLogger("anaconda")
@@ -369,8 +370,12 @@ class LuksPassphraseWindow:
                 if len(passphrase) < self.minLength:
                     ButtonChoiceWindow(self.screen,
                                        _("Error with passphrase"),
-                                       _("The passphrase must be at least "
-                                         "%d characters long.") % (self.minLength,),
+                                       P_("The passphrase must be at least "
+                                          "%d character long.",
+                                          "The passphrase must be at least "
+                                          "%d characters long.",
+                                          self.minLength)
+                                         % (self.minLength,),
                                        buttons=[TEXT_OK_BUTTON])
                     passphraseentry.set("")
                     confirmentry.set("")
diff --git a/vnc.py b/vnc.py
index 3e5d813..db119d0 100644
--- a/vnc.py
+++ b/vnc.py
@@ -32,6 +32,7 @@ import subprocess
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
+P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
 
 import logging
 log = logging.getLogger("anaconda")
@@ -185,7 +186,9 @@ class VncServer:
             else:
                 log.critical(err)
                 sys.exit(1)
-        self.log.error(_("Giving up attempting to connect after %d tries!\n" % maxTries ))
+        self.log.error(P_("Giving up attempting to connect after %d try!\n",
+                          "Giving up attempting to connect after %d tries!\n",
+                          maxTries) % (maxTries,))
         return False
 
     def VNCListen(self):
diff --git a/yuminstall.py b/yuminstall.py
index 0e7a4da..b39ecb9 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -51,6 +51,7 @@ import packages
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
+P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
 
 import network
 
@@ -81,10 +82,7 @@ def size_string (size):
         size = size / 1024
         retval = _("%s KB") %(number_format(size),)
     else:
-        if size == 1:
-            retval = _("%s Byte") %(number_format(size),)
-        else:
-            retval = _("%s Bytes") %(number_format(size),)
+        retval = P_("%s Byte", "%s Bytes", size) % (number_format(size),)
 
     return to_unicode(retval)
 
@@ -209,8 +207,10 @@ class AnacondaCallback:
             self.doneFiles += len(hdr[rpm.RPMTAG_BASENAMES])
 
             if self.donepkgs <= self.numpkgs:
-                self.progress.set_text(_("%s of %s packages completed")
-                                       %(self.donepkgs, self.numpkgs))
+                self.progress.set_text(P_("Packages completed: %d of %d",
+                                          "Packages completed: %d of %d",
+                                          self.numpkgs)
+                                       % (self.donepkgs, self.numpkgs,))
             self.progress.set_fraction(float(self.doneSize / self.totalSize))
             self.progress.processEvents()
 
-- 
1.6.2.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]