comparison 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
comparison
equal deleted inserted replaced
47:e8eb1f93c4e7 48:1eb92ab03287
238 static void 238 static void
239 update_notification(PkuiIcon *self, guint updates_normal, 239 update_notification(PkuiIcon *self, guint updates_normal,
240 guint updates_important) 240 guint updates_important)
241 { 241 {
242 gchar *message; 242 gchar *message;
243 gchar *message_a;
244 gchar *message_b;
243 gchar *title = updates_important ? 245 gchar *title = updates_important ?
246 /* TRANSLATORS: This is a message without number mentioned */
244 ngettext("Important Software Update", "Important Software Updates", 247 ngettext("Important Software Update", "Important Software Updates",
245 updates_important + updates_normal) : 248 updates_important + updates_normal) :
249 /* TRANSLATORS: This is a message without number mentioned */
246 ngettext("Software Update", "Software Updates", updates_important + 250 ngettext("Software Update", "Software Updates", updates_important +
247 updates_normal); 251 updates_normal);
248 gchar *icon = updates_important ? "software-update-urgent" : 252 gchar *icon = updates_important ? "software-update-urgent" :
249 "software-update-available"; 253 "software-update-available";
250 254
251 if (updates_important > 0) 255 if (updates_important > 0) {
252 if (updates_normal > 0) 256 if (updates_normal > 0) {
253 message = g_strdup_printf(ngettext("There are %d " 257 message_a = g_strdup_printf(
254 "software updates available, %d of them is " 258 /*
255 "important.", "There are %d software updates " 259 * TRANSLATORS: This sentence contains two plurals.
256 "available, %d of them are important.", 260 * Texts related to these plurals are mixed. That is
257 updates_important), 261 * why it is split in three parts. Fill first two parts
258 updates_normal + updates_important, 262 * as you need, and use them as %s in the last one to
263 * construct a sentence. Note that if the first form of
264 * plural relates only to singular form, it is never
265 * used, and dedicated shorter sentences are used. */
266 ngettext("There is %d software update available,",
267 "There are %d software updates available,",
268 updates_normal + updates_important),
269 updates_normal + updates_important);
270 /*
271 * TRANSLATORS: This is the sentence part in the
272 * middle, form of which is related to the first
273 * number. If your language does not need it, simply
274 * use it as space or so. */
275 message_b = ngettext("of it", "of them",
276 updates_normal + updates_important);
277 message = g_strdup_printf(
278 /*
279 * TRANSLATORS: This forms the sentence. If you need to
280 * swap parts, use %3$s and %1$s etc. Plurals are
281 * related to second number. */
282 ngettext("%s %d %s is important.",
283 "%s %d %s are important.", updates_important),
284 message_a, updates_important, message_b);
285 g_free(message_a);
286 } else {
287 message = g_strdup_printf(ngettext("There is %d "
288 "important software update available.",
289 "There are %d important software updates "
290 "available.", updates_important),
259 updates_important); 291 updates_important);
260 else 292 }
261 message = g_strdup_printf(ngettext("There is an " 293 } else {
262 "important software update available.", "There are " 294 message = g_strdup_printf(ngettext("There is %d software "
263 "%d important software updates available.", 295 "update available.",
264 updates_important), updates_important); 296 "There are %d software updates available.",
265 else
266 message = g_strdup_printf(ngettext("There is a software update "
267 "available.", "There are %d software updates available.",
268 updates_normal), updates_normal); 297 updates_normal), updates_normal);
298 }
269 299
270 gtk_status_icon_set_tooltip(self->priv->status_icon, message); 300 gtk_status_icon_set_tooltip(self->priv->status_icon, message);
271 gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon); 301 gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon);
272 gtk_status_icon_set_visible(self->priv->status_icon, TRUE); 302 gtk_status_icon_set_visible(self->priv->status_icon, TRUE);
273 303