After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 308169 - Meld dirdiff message(s) may need ngettext support
Meld dirdiff message(s) may need ngettext support
Status: VERIFIED FIXED
Product: meld
Classification: Other
Component: dirdiff
unspecified
Other All
: Normal normal
: ---
Assigned To: Stephen Kennedy
Stephen Kennedy
Depends on:
Blocks:
 
 
Reported: 2005-06-18 09:58 UTC by Christian Rose
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Christian Rose 2005-06-18 09:58:55 UTC
#. singular,plural
#: dirdiff.py:558
msgid ""
"second,seconds:minute,minutes:hour,hours:day,days:week,weeks:month,months:"
"year,years"

I think this might need the use of ngettext(), i.e.
ngettext("%d second", "%d seconds", nbr_of_seconds), and so on. Please see
http://developer.gnome.org/doc/tutorials/gnome-i18n/developer.html#plurals.
Comment 1 Stephen Kennedy 2005-06-20 11:59:21 UTC
Unfortunately that seems to only be available with python >= 2.3.
I had hoped to make the 1.0 release compatible with 2.2

Is there an idiom for ngettext like "N_" is to "_"?
Comment 2 Danilo Segan 2005-06-20 17:48:18 UTC
No, there's no idiom: one would commonly just use "ngettext = gettext.ngettext"
in Python, and add appropriate keyword to xgettext command (like xgettext
--keyword=ngettext:1,2): intltool does this for you, though.

If it's not available, I figure it's ok to simply:
  if "ngettext" in dir(gettext):
      ngettext = gettext.ngettext
  else:
      ngettext = lambda singular, plural, number: gettext.gettext(plural)

This means that it wouldn't work for lesser than Python 2.3 (and even then
translators would have the option to hack around it by using only translation of
"plural" string), but I'm always comfortable with requiring better software
platform for I18N purposes (if the requirement itself is not unreasonable, such
as requiring software from CVS).
Comment 3 Stephen Kennedy 2005-06-21 10:00:40 UTC
That array needs to be indexable, so it needs to have "delayed"
translation like N_. From looking I should be able to use the following 
code with --keyword=N_ngettext:1,2

N_ngettext = lambda a,b : a,b
values = [
 N_ngettext("%i second","%i seconds"),
 N_ngettext("%i minute","%i minutes"),
 N_ngettext("%i hour","%i hours"),
 N_ngettext("%i day","%i days"),
 N_ngettext("%i week","%i weeks"),
 N_ngettext("%i month","%i months"),
 N_ngettext("%i year","%i years") ]

singular, plural = values[index]
print ngettext(singular, plural, number) % number
Comment 4 Danilo Segan 2005-06-21 11:12:56 UTC
Yeah, you could do that, or even:

values = [
 ngettext("%i second","%i seconds", number),
 ngettext("%i minute","%i minutes", number),
 ngettext("%i hour","%i hours", number),
 ngettext("%i day","%i days", number),
 ngettext("%i week","%i weeks", number),
 ngettext("%i month","%i months", number),
 ngettext("%i year","%i years", number) ]

print values[index] % number

Though this may be a bit slower depending on how often "values" gets evaluated.

For how to set custom keywords for xgettext using intltool, look at
intltool/README (and especially po/Makevars section).
Comment 6 Stephen Kennedy 2006-11-19 11:05:37 UTC
Batch close of old bugs.