Mercurial > projects > pk-update-icon
diff pkui-icon.c @ 48:1eb92ab03287
Avoid passing more arguments to g_strdup_printf() than specified in the format
Avoid passing more arguments to g_strdup_printf() than specified in the format
depending on the number of updates.
Split sentences with two plural forms up, otherwise they cannot be formatted
properly.
author | Stanislav Brabec <sbrabec@suse.com> |
---|---|
date | Thu, 18 Jun 2015 22:55:08 +0200 |
parents | aa5d3752091d |
children | 7de92a24e86c |
line wrap: on
line diff
--- a/pkui-icon.c Thu Jun 18 22:20:45 2015 +0200 +++ b/pkui-icon.c Thu Jun 18 22:55:08 2015 +0200 @@ -240,32 +240,62 @@ guint updates_important) { gchar *message; + gchar *message_a; + gchar *message_b; gchar *title = updates_important ? + /* TRANSLATORS: This is a message without number mentioned */ ngettext("Important Software Update", "Important Software Updates", updates_important + updates_normal) : + /* TRANSLATORS: This is a message without number mentioned */ ngettext("Software Update", "Software Updates", updates_important + updates_normal); gchar *icon = updates_important ? "software-update-urgent" : "software-update-available"; - if (updates_important > 0) - if (updates_normal > 0) - message = g_strdup_printf(ngettext("There are %d " - "software updates available, %d of them is " - "important.", "There are %d software updates " - "available, %d of them are important.", - updates_important), - updates_normal + updates_important, + if (updates_important > 0) { + if (updates_normal > 0) { + message_a = g_strdup_printf( + /* + * TRANSLATORS: This sentence contains two plurals. + * Texts related to these plurals are mixed. That is + * why it is split in three parts. Fill first two parts + * as you need, and use them as %s in the last one to + * construct a sentence. Note that if the first form of + * plural relates only to singular form, it is never + * used, and dedicated shorter sentences are used. */ + ngettext("There is %d software update available,", + "There are %d software updates available,", + updates_normal + updates_important), + updates_normal + updates_important); + /* + * TRANSLATORS: This is the sentence part in the + * middle, form of which is related to the first + * number. If your language does not need it, simply + * use it as space or so. */ + message_b = ngettext("of it", "of them", + updates_normal + updates_important); + message = g_strdup_printf( + /* + * TRANSLATORS: This forms the sentence. If you need to + * swap parts, use %3$s and %1$s etc. Plurals are + * related to second number. */ + ngettext("%s %d %s is important.", + "%s %d %s are important.", updates_important), + message_a, updates_important, message_b); + g_free(message_a); + } else { + message = g_strdup_printf(ngettext("There is %d " + "important software update available.", + "There are %d important software updates " + "available.", updates_important), updates_important); - else - message = g_strdup_printf(ngettext("There is an " - "important software update available.", "There are " - "%d important software updates available.", - updates_important), updates_important); - else - message = g_strdup_printf(ngettext("There is a software update " - "available.", "There are %d software updates available.", + } + } else { + message = g_strdup_printf(ngettext("There is %d software " + "update available.", + "There are %d software updates available.", updates_normal), updates_normal); + } gtk_status_icon_set_tooltip(self->priv->status_icon, message); gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon);