GNOME Bugzilla – Bug 308169
Meld dirdiff message(s) may need ngettext support
Last modified: 2009-08-15 18:40:50 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.
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 "_"?
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).
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
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).
Fix checked into as http://cvs.gnome.org/viewcvs/meld/dirdiff.py?r1=1.53.2.3&r2=1.53.2.4&only_with_tag=branch-0_9 http://cvs.gnome.org/viewcvs/meld/meld?r1=1.18.2.1&r2=1.18.2.2&only_with_tag=branch-0_9 Can you verify, thanks?
Batch close of old bugs.