[empathy: 6/11] Reduce format string duplication for part notifications.



commit 08f02f53a10fd653cac56e23817f3c40d636ca5e
Author: Will Thompson <will thompson collabora co uk>
Date:   Thu Jun 18 21:16:51 2009 +0100

    Reduce format string duplication for part notifications.
    
    Xavier suggested that just appending " (%s)" to the common prefix when
    there is a message is probably okay from a translation point of view, as
    long as there's a comment to translators.

 libempathy-gtk/empathy-chat.c |   83 ++++++++++++++++------------------------
 1 files changed, 33 insertions(+), 50 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index c3fc794..04b0cbd 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -1159,60 +1159,43 @@ build_part_message (guint        reason,
 		    const gchar *actor,
 		    const gchar *message)
 {
+	GString *s = g_string_new ("");
+
 	/* Having an actor only really makes sense for a few actions... */
-	if (message == NULL) {
-		switch (reason) {
-		case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
-			return g_strdup_printf (_("%s has disconnected"), name);
-		case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
-			if (actor != NULL) {
-				return g_strdup_printf (
-					_("%s was kicked by %s"), name, actor);
-			} else {
-				return g_strdup_printf (_("%s was kicked"),
-					name);
-			}
-		case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
-			if (actor != NULL) {
-				return g_strdup_printf (
-					_("%s was banned by %s"), name, actor);
-			} else {
-				return g_strdup_printf (_("%s was banned"),
-					name);
-			}
-		default:
-			return g_strdup_printf (_("%s has left the room"),
-				name);
+	switch (reason) {
+	case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
+		g_string_append_printf (s, _("%s has disconnected"), name);
+		break;
+	case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
+		if (actor != NULL) {
+			g_string_append_printf (s, _("%s was kicked by %s"),
+				name, actor);
+		} else {
+			g_string_append_printf (s, _("%s was kicked"), name);
 		}
-	} else {
-		switch (reason) {
-		case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
-			return g_strdup_printf (_("%s has disconnected (%s)"),
-				name, message);
-		case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
-			if (actor != NULL) {
-				return g_strdup_printf (
-					_("%s was kicked by %s (%s)"), name,
-					actor, message);
-			} else {
-				return g_strdup_printf (
-					_("%s was kicked (%s)"),
-					name, message);
-			}
-		case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
-			if (actor != NULL) {
-				return g_strdup_printf (
-					_("%s was banned by %s (%s)"), name,
-					actor, message);
-			} else {
-				return g_strdup_printf (_("%s was banned (%s)"),
-					name, message);
-			}
-		default:
-			return g_strdup_printf (_("%s has left the room (%s)"),
-				name, message);
+		break;
+	case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
+		if (actor != NULL) {
+			g_string_append_printf (s, _("%s was banned by %s"),
+				name, actor);
+		} else {
+			g_string_append_printf (s, _("%s was banned"), name);
 		}
+		break;
+	default:
+		g_string_append_printf (s, _("%s has left the room"), name);
 	}
+
+	if (message != NULL) {
+		/* Note to translators: this string is appended to
+		 * notifications like "foo has left the room", with the message
+		 * given by the user living the room. If this poses a problem,
+		 * please let us know. :-)
+		 */
+		g_string_append_printf (s, _(" (%s)"), message);
+	}
+
+	return g_string_free (s, FALSE);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]