[rhythmbox] status-icon: use direction-neutral templates when necessary (bug #609767)



commit e478d4994e83b6a3a7eac6805c2998e23cf83664
Author: Uri Sivan <tartif gmail com>
Date:   Sun Feb 14 15:41:30 2010 +1000

    status-icon: use direction-neutral templates when necessary (bug #609767)
    
    When the localised template strings ("by x", "from y") are in one
    direction but the artist and album strings being substituted in are in
    the other, the localised templates will look weird and wrong.  Instead,
    we use direction neutral templates, just separating the album and artist
    with a slash, so what's displayed at least makes sense.

 plugins/status-icon/rb-status-icon-plugin.c |   65 +++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 8 deletions(-)
---
diff --git a/plugins/status-icon/rb-status-icon-plugin.c b/plugins/status-icon/rb-status-icon-plugin.c
index b94c057..41c59be 100644
--- a/plugins/status-icon/rb-status-icon-plugin.c
+++ b/plugins/status-icon/rb-status-icon-plugin.c
@@ -37,6 +37,8 @@
 
 #include <X11/Xatom.h>
 
+#include <pango/pango-bidi-type.h>
+
 #ifdef HAVE_NOTIFY
 #include <libnotify/notify.h>
 #endif
@@ -639,6 +641,50 @@ rb_status_icon_plugin_set_tooltip (GtkWidget        *widget,
 /* information on current track */
 
 static void
+get_artist_album_templates (const char *artist,
+			    const char *album,
+			    const char **artist_template,
+			    const char **album_template)
+{
+	PangoDirection tag_dir;
+	PangoDirection template_dir;
+
+	/* Translators: by Artist */
+	*artist_template = _("by <i>%s</i>");
+	/* Translators: from Album */
+	*album_template = _("from <i>%s</i>");
+
+	/* find the direction (left-to-right or right-to-left) of the
+	 * track's tags and the localized templates
+	 */
+	if (artist != NULL && artist[0] != '\0') {
+		tag_dir = pango_find_base_dir (artist, -1);
+		template_dir = pango_find_base_dir (*artist_template, -1);
+	} else if (album != NULL && album[0] != '\0') {
+		tag_dir = pango_find_base_dir (album, -1);
+		template_dir = pango_find_base_dir (*album_template, -1);
+	} else {
+		return;
+	}
+
+	/* if the track's tags and the localized templates have a different
+	 * direction, switch to direction-neutral templates in order to improve
+	 * display.
+	 * text can have a neutral direction, this condition only applies when
+	 * both directions are defined and they are conflicting.
+	 * https://bugzilla.gnome.org/show_bug.cgi?id=609767
+	 */
+	if (((tag_dir == PANGO_DIRECTION_LTR) && (template_dir == PANGO_DIRECTION_RTL)) ||
+	    ((tag_dir == PANGO_DIRECTION_RTL) && (template_dir == PANGO_DIRECTION_LTR))) {
+		/* these strings should not be localized, they must be
+		 * locale-neutral and direction-neutral
+		 */
+		*artist_template = "<i>%s</i>";
+		*album_template = "/ <i>%s</i>";
+	}
+}
+
+static void
 update_current_playing_data (RBStatusIconPlugin *plugin, RhythmDBEntry *entry)
 {
 	GValue *value;
@@ -648,6 +694,9 @@ update_current_playing_data (RBStatusIconPlugin *plugin, RhythmDBEntry *entry)
 	char *title = NULL;
 	GString *secondary;
 
+	const char *artist_template = NULL;
+	const char *album_template = NULL;
+
 	g_free (plugin->priv->current_title);
 	g_free (plugin->priv->current_album_and_artist);
 	plugin->priv->current_title = NULL;
@@ -670,12 +719,6 @@ update_current_playing_data (RBStatusIconPlugin *plugin, RhythmDBEntry *entry)
 		artist = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST));
 	}
 
-	if (artist != NULL && artist[0] != '\0') {
-		/* Translators: by Artist */
-		g_string_append_printf (secondary, _("by <i>%s</i>"), artist);
-	}
-	g_free (artist);
-
 	/* get album, preferring streaming song details */
 	value = rhythmdb_entry_request_extra_metadata (plugin->priv->db,
 						       entry,
@@ -688,12 +731,18 @@ update_current_playing_data (RBStatusIconPlugin *plugin, RhythmDBEntry *entry)
 		album = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM));
 	}
 
+	get_artist_album_templates (artist, album, &artist_template, &album_template);
+
+	if (artist != NULL && artist[0] != '\0') {
+		g_string_append_printf (secondary, artist_template, artist);
+	}
+	g_free (artist);
+
 	if (album != NULL && album[0] != '\0') {
 		if (secondary->len != 0)
 			g_string_append_c (secondary, ' ');
 
-		/* Translators: from Album */
-		g_string_append_printf (secondary, _("from <i>%s</i>"), album);
+		g_string_append_printf (secondary, album_template, album);
 	}
 	g_free (album);
 



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