ngettext should be used in void delete_finished_tasks()

Bug #1549517 reported by Mingye Wang
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Agenda
New
Undecided
Unassigned

Bug Description

https://bazaar.launchpad.net/~agenda-developers/agenda-tasks/trunk/view/head:/src/AgendaWindow.vala#L413:

show_notification (_("Task finished"), counter > 1 ? counter.to_string () + _(" tasks have been removed") : _("A task has been removed"));

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

I don't get the point, sorry.
Could you explain what's wrong?

Revision history for this message
Mingye Wang (artoria2e5) wrote :

Using such special cases is a terrible idea in l10n, since many languages have all kinds of different plural forms, while _(" tasks have been removed") assumes only two forms: n<=1 and n>1.

For example (from https://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html), Russian has three plural forms: `nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);`

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

What do you suggest?

Revision history for this message
Mingye Wang (artoria2e5) wrote :

// char * ngettext (const char * msgid, const char * msgid_plural,
         unsigned long int n);

show_notification (_("Task finished"), N_(counter.to_string () + " tasks have been removed", "A task has been removed", counter));

Of course, you can do better and use some format strings, since fmt strs can give translators more flexibility and more sense about what they are translating. See https://www.gnu.org/software/gettext/manual/gettext.html#Preparing-Strings. Unfortunately I don't want to look at things like snprintf for now.

Revision history for this message
Mingye Wang (artoria2e5) wrote :

Oops, I shouldn't be looking at the C gettext manpage.

Regardless, there is ngettext in Glib (vala):
http://valadoc.org/#!api=glib-2.0/GLib.ngettext
// public unowned string ngettext (string msgid, string msgid_plural, ulong n)
// basically the same thing

And you should be able to do format strings like this now:
show_notification (_("Task finished"), N_("%d tasks have been removed", "A task has been removed", counter).printf(counter));

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.