[totem] Use Unicode strings for translatable messages in Python plugins



commit 42679707cd3281843ea2f347785ff52e682ff196
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Nov 18 21:09:57 2010 +0000

    Use Unicode strings for translatable messages in Python plugins
    
    Convert all the translatable strings in the Python plugins to use Unicode
    strings, and ensure that all the .py files are UTF-8 encoded. This fixes
    gettext for translatable strings which use Unicode characters (such as
    ellipses).
    
    This also introduces Unicode characters to a few more strings, for
    consistency.
    
    Closes: bgo#619039

 src/plugins/coherence_upnp/coherence_upnp.py |   14 +++++----
 src/plugins/iplayer/iplayer.py               |    8 +++---
 src/plugins/iplayer/iplayer2.py              |    5 ++-
 src/plugins/jamendo/jamendo.py               |   38 +++++++++++++-------------
 src/plugins/opensubtitles/opensubtitles.py   |   26 +++++++++--------
 src/plugins/pythonconsole/pythonconsole.py   |   16 +++++-----
 6 files changed, 56 insertions(+), 51 deletions(-)
---
diff --git a/src/plugins/coherence_upnp/coherence_upnp.py b/src/plugins/coherence_upnp/coherence_upnp.py
index 15f8cb8..29d74d5 100644
--- a/src/plugins/coherence_upnp/coherence_upnp.py
+++ b/src/plugins/coherence_upnp/coherence_upnp.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 # Licensed under the MIT license
 # http://opensource.org/licenses/mit-license.php
 
@@ -79,10 +81,10 @@ class UPnPClient(gobject.GObject, Peas.Activatable):
         if not hasattr(self, 'context_no_delete'):
             self.context_no_delete = gtk.Menu()
             # Translators: this refers to a media file
-            play_menu = gtk.MenuItem(_("Play"))
+            play_menu = gtk.MenuItem(_(u"Play"))
             play_menu.connect("activate", action, 'item.play')
             # Translators: this refers to a media file
-            enqueue_menu = gtk.MenuItem(_("Enqueue"))
+            enqueue_menu = gtk.MenuItem(_(u"Enqueue"))
             enqueue_menu.connect("activate", action, 'item.enqueue')
             self.context_no_delete.append(play_menu)
             self.context_no_delete.append(enqueue_menu)
@@ -91,16 +93,16 @@ class UPnPClient(gobject.GObject, Peas.Activatable):
         if not hasattr(self, 'context_with_delete'):
             self.context_with_delete = gtk.Menu()
             # Translators: this refers to a media file
-            play_menu = gtk.MenuItem(_("Play"))
+            play_menu = gtk.MenuItem(_(u"Play"))
             play_menu.connect("activate", action, 'item.play')
             # Translators: this refers to a media file
-            enqueue_menu = gtk.MenuItem(_("Enqueue"))
+            enqueue_menu = gtk.MenuItem(_(u"Enqueue"))
             enqueue_menu.connect("activate", action, 'item.enqueue')
             self.context_with_delete.append(play_menu)
             self.context_with_delete.append(enqueue_menu)
             self.context_with_delete.append(gtk.SeparatorMenuItem())
             # Translators: this refers to a media file
-            menu = gtk.MenuItem(_("Delete"))
+            menu = gtk.MenuItem(_(u"Delete"))
             menu.connect("activate", action, 'item.delete')
             self.context_with_delete.append(menu)
             self.context_with_delete.show_all()
@@ -111,7 +113,7 @@ class UPnPClient(gobject.GObject, Peas.Activatable):
             self.context = self.context_no_delete
 
     def do_activate (self):
-        self.totem_object.add_sidebar_page ("upnp-coherence", _("Coherence DLNA/UPnP Client"), self.ui.window)
+        self.totem_object.add_sidebar_page ("upnp-coherence", _(u"Coherence DLNA/UPnP Client"), self.ui.window)
 
         def load_and_play(url):
             self.totem_object.add_to_playlist_and_play (url, '', True)
diff --git a/src/plugins/iplayer/iplayer.py b/src/plugins/iplayer/iplayer.py
index 8eddc8c..ae86284 100644
--- a/src/plugins/iplayer/iplayer.py
+++ b/src/plugins/iplayer/iplayer.py
@@ -38,7 +38,7 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 		self.tv = iplayer2.feed ('tv')
 
 		# Add the interface to Totem's sidebar
-		self.totem.add_sidebar_page ("iplayer", _("BBC iPlayer"), container)
+		self.totem.add_sidebar_page ("iplayer", _(u"BBC iPlayer"), container)
 
 		# Get the channel category listings
 		self.populate_channel_list (self.tv, self.tv_tree_store)
@@ -63,7 +63,7 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 	def _populate_channel_list_cb (self, tree_store, parent_path, values):
 		# Callback from PopulateChannelsThread to add stuff to the tree store
 		if values == None:
-			self.totem.action_error (_('Error listing channel categories'), _('There was an unknown error getting the list of television channels available on BBC iPlayer.'))
+			self.totem.action_error (_(u'Error listing channel categories'), _(u'There was an unknown error getting the list of television channels available on BBC iPlayer.'))
 			return False
 
 		parent_iter = tree_store.get_iter (parent_path)
@@ -71,7 +71,7 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 
 		# Append a dummy child row so that the expander's visible; we can
 		# then queue off the expander to load the programme listing for this category
-		tree_store.append (category_iter, [_('Loadingâ?¦'), None, None])
+		tree_store.append (category_iter, [_(u'Loadingâ?¦'), None, None])
 
 		return False
 
@@ -116,7 +116,7 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 		# Callback from PopulateProgrammesThread to add stuff to the tree store
 		if values == None:
 			# Translators: the "programme feed" is the list of TV shows available to watch online
-			self.totem.action_error (_('Error getting programme feed'), _('There was an error getting the list of programmes for this channel and category combination.'))
+			self.totem.action_error (_(u'Error getting programme feed'), _(u'There was an error getting the list of programmes for this channel and category combination.'))
 			return False
 
 		category_iter = tree_store.get_iter (category_path)
diff --git a/src/plugins/iplayer/iplayer2.py b/src/plugins/iplayer/iplayer2.py
index 0a75789..6c5f3b4 100644
--- a/src/plugins/iplayer/iplayer2.py
+++ b/src/plugins/iplayer/iplayer2.py
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 
 # Python libs
 import re, os
@@ -295,8 +296,8 @@ class NoItemsError(Exception):
         self.reason = reason
 
     def __str__(self):
-        reason = self.reason or '<no reason given>'
-        return _('Programme unavailable ("%s")') % (reason)
+        reason = self.reason or _(u'<no reason given>')
+        return _(u'Programme unavailable ("%s")') % (reason)
 
 class memoize(object):
     def __init__(self, func):
diff --git a/src/plugins/jamendo/jamendo.py b/src/plugins/jamendo/jamendo.py
index 374803c..17af39c 100644
--- a/src/plugins/jamendo/jamendo.py
+++ b/src/plugins/jamendo/jamendo.py
@@ -55,7 +55,7 @@ except ImportError:
             message_type=Gtk.MessageType.ERROR,
             buttons=Gtk.ButtonsType.OK
         )
-        dlg.set_markup(_('You need to install the Python simplejson module.'))
+        dlg.set_markup(_(u'You need to install the Python simplejson module.'))
         dlg.run()
         dlg.destroy()
         raise
@@ -124,7 +124,7 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
 
         self.reset()
         container.show_all()
-        self.totem.add_sidebar_page("jamendo", _("Jamendo"), container)
+        self.totem.add_sidebar_page("jamendo", _(u"Jamendo"), container)
 
     def do_deactivate(self):
         """
@@ -257,23 +257,23 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
                     8, 1, 1)
         # format title
         title  = '<b>%s</b>\n' % self._format_str(album['name'])
-        title += _('Artist: %s') % self._format_str(album['artist_name'])
+        title += _(u'Artist: %s') % self._format_str(album['artist_name'])
         # format duration
         dur = self._format_duration(album['duration'])
         # format tooltip
         try:
             # Translators: this is the release date of an album in Python strptime format
-            release = time.strptime(album['dates']['release'][0:10], _('%Y-%m-%d'))
+            release = time.strptime(album['dates']['release'][0:10], _(u'%Y-%m-%d'))
             # Translators: this is the release time of an album in Python strftime format
-            release = time.strftime(_('%x'), release)
+            release = time.strftime(_(u'%x'), release)
         except:
             release = ''
         tip = '\n'.join([
             '<b>%s</b>' % self._format_str(album['name']),
-            _('Artist: %s') % self._format_str(album['artist_name']),
-            _('Genre: %s') % self._format_str(album['genre']),
-            _('Released on: %s') % release,
-            _('License: %s') % self._format_str(album['license'][0]),
+            _(u'Artist: %s') % self._format_str(album['artist_name']),
+            _(u'Genre: %s') % self._format_str(album['genre']),
+            _(u'Released on: %s') % release,
+            _(u'License: %s') % self._format_str(album['license'][0]),
         ])
         # append album row
         parent = treeview.get_model().append(None,
@@ -286,16 +286,16 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
             # track title
             # Translators: this is the title of a track in Python format
             # (first argument is the track number, second is the track title)
-            tt = ('<small>%s</small>' % _('%02d. %s')) % \
+            tt = ('<small>%s</small>' % _(u'%02d. %s')) % \
                 (i+1, self._format_str(track['name']))
             # track duration
             td = self._format_duration(track['duration'])
             # track tooltip
             tip = '\n'.join([
                 '<b>%s</b>' %  self._format_str(track['name']),
-                _('Album: %s') % self._format_str(album['name']),
-                _('Artist: %s') % self._format_str(album['artist_name']),
-                _('Duration: %s') % td,
+                _(u'Album: %s') % self._format_str(album['name']),
+                _(u'Artist: %s') % self._format_str(album['artist_name']),
+                _(u'Duration: %s') % td,
             ])
             # append track
             treeview.get_model().append(parent, [track, icon, tt, td, tip])
@@ -352,7 +352,7 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
         self.progressbars[tab_index].show()
         self.progressbars[tab_index].set_fraction(0.0)
         self.progressbars[tab_index].set_text(
-            _('Fetching albums, please wait...')
+            _(u'Fetching albums, please waitâ?¦')
         )
         lcb = (self.on_fetch_albums_loop, self.current_treeview)
         dcb = (self.on_fetch_albums_done, self.current_treeview)
@@ -407,13 +407,13 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
                 except:
                     reason = str(exc)
             reason = reason.capitalize()
-            msg = _('Failed to connect to Jamendo server.\n%s.') % reason
+            msg = _(u'Failed to connect to Jamendo server.\n%s.') % reason
         elif hasattr(exc, 'code'):
-            msg = _('The Jamendo server returned code %s.') % exc.code
+            msg = _(u'The Jamendo server returned code %s.') % exc.code
         else:
             msg = str(exc)
 
-        self.totem.action_error(_('An error occurred while fetching albums.'), msg)
+        self.totem.action_error(_(u'An error occurred while fetching albums.'), msg)
 
     def on_search_entry_activate(self, *args):
         """
@@ -615,10 +615,10 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasGtk.Configurable):
             if secs >= 3600:
                 # Translators: time formatting (in Python strftime format) for the Jamendo plugin
                 # for times longer than an hour
-                return time.strftime(_('%H:%M:%S'), time.gmtime(secs))
+                return time.strftime(_(u'%H:%M:%S'), time.gmtime(secs))
             # Translators: time formatting (in Python strftime format) for the Jamendo plugin
             # for times shorter than an hour
-            return time.strftime(_('%M:%S'), time.gmtime(secs))
+            return time.strftime(_(u'%M:%S'), time.gmtime(secs))
         except:
             return ''
 
diff --git a/src/plugins/opensubtitles/opensubtitles.py b/src/plugins/opensubtitles/opensubtitles.py
index aa341cd..ddf01ed 100644
--- a/src/plugins/opensubtitles/opensubtitles.py
+++ b/src/plugins/opensubtitles/opensubtitles.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 from gi.repository import Peas
 from gi.repository import Gtk
 from gi.repository import Gdk
@@ -242,7 +244,7 @@ class OpenSubtitlesModel(object):
             if self.token:
                 return True
 
-        self.message = _('Could not contact the OpenSubtitles website')
+        self.message = _(u'Could not contact the OpenSubtitles website')
 
         return False
 
@@ -258,12 +260,12 @@ class OpenSubtitlesModel(object):
             try:
                 result = self.server.SearchSubtitles(self.token, [searchdata])
             except xmlrpclib.ProtocolError:
-                self.message = _('Could not contact the OpenSubtitles website')
+                self.message = _(u'Could not contact the OpenSubtitles website')
 
             if result.get('data'):
                 return result['data']
             else:
-                self.message = _('No results found')
+                self.message = _(u'No results found')
 
         return None
 
@@ -275,13 +277,13 @@ class OpenSubtitlesModel(object):
             try:
                 result = self.server.DownloadSubtitles(self.token, [subtitleId])
             except xmlrpclib.ProtocolError:
-                self.message = _('Could not contact the OpenSubtitles website')
+                self.message = _(u'Could not contact the OpenSubtitles website')
 
             if result and result.get('status') == OK200:
                 try:
                     subtitle64 = result['data'][0]['data']
                 except:
-                    self.message = _('Could not contact the OpenSubtitles website')
+                    self.message = _(u'Could not contact the OpenSubtitles website')
                     return None
 
                 import StringIO, gzip, base64
@@ -369,18 +371,18 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         self.treeview.set_model(self.liststore)
         self.treeview.set_headers_visible(False)
         renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
-        column = Gtk.TreeViewColumn(_("Subtitles"), renderer, text=0)
+        column = Gtk.TreeViewColumn(_(u"Subtitles"), renderer, text=0)
         column.set_resizable(True)
         column.set_expand(True)
         self.treeview.append_column(column)
 	# translators comment:
 	# This is the file-type of the subtitle file detected
-        column = Gtk.TreeViewColumn(_("Format"), renderer, text=1)
+        column = Gtk.TreeViewColumn(_(u"Format"), renderer, text=1)
         column.set_resizable(False)
         self.treeview.append_column(column)
 	# translators comment:
 	# This is a rating of the quality of the subtitle
-        column = Gtk.TreeViewColumn(_("Rating"), renderer, text=2)
+        column = Gtk.TreeViewColumn(_(u"Rating"), renderer, text=2)
         column.set_resizable(False)
         self.treeview.append_column(column)
 
@@ -421,8 +423,8 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         self.os_action_group = Gtk.ActionGroup(name='OpenSubtitles')
 
         self.action = Gtk.Action(name='opensubtitles',
-                                 label=_('_Download Movie Subtitles...'),
-                                 tooltip=_("Download movie subtitles from OpenSubtitles"),
+                                 label=_(u'_Download Movie Subtitlesâ?¦'),
+                                 tooltip=_(u"Download movie subtitles from OpenSubtitles"),
                                  stock_id=None)
 
         self.os_action_group.add_action(self.action)
@@ -481,7 +483,7 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         thread.start()
         gobject.idle_add(self.os_populate_treeview)
 
-        self.progress.set_text(_('Searching subtitles...'))
+        self.progress.set_text(_(u'Searching subtitlesâ?¦'))
         gobject.timeout_add(350, self.os_progress_bar_increment, thread)
 
     def os_populate_treeview(self):
@@ -539,7 +541,7 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
             thread.start()
             gobject.idle_add(self.os_save_subtitles, filename)
 
-            self.progress.set_text(_('Downloading the subtitles...'))
+            self.progress.set_text(_(u'Downloading the subtitlesâ?¦'))
             gobject.timeout_add(350, self.os_progress_bar_increment, thread)
         else:
             #warn user!
diff --git a/src/plugins/pythonconsole/pythonconsole.py b/src/plugins/pythonconsole/pythonconsole.py
index cb54444..7929e96 100644
--- a/src/plugins/pythonconsole/pythonconsole.py
+++ b/src/plugins/pythonconsole/pythonconsole.py
@@ -82,17 +82,17 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 
 		data['action_group'] = Gtk.ActionGroup(name = 'Python')
 		
-		action = Gtk.Action(name = 'Python', label = 'Python', tooltip = _('Python Console Menu'))
+		action = Gtk.Action(name = 'Python', label = 'Python', tooltip = _(u'Python Console Menu'))
 		data['action_group'].add_action(action)
 
-		action = Gtk.Action(name = 'PythonConsole', label = _('_Python Console'),
-		                    tooltip = _("Show Totem's Python console"),
+		action = Gtk.Action(name = 'PythonConsole', label = _(u'_Python Console'),
+		                    tooltip = _(u"Show Totem's Python console"),
 		                    stock_id = 'gnome-mime-text-x-python')
 		action.connect('activate', self.show_console)
 		data['action_group'].add_action(action)
 
-		action = Gtk.Action(name = 'PythonDebugger', label = _('Python Debugger'),
-				    tooltip = _("Enable remote Python debugging with rpdb2"))
+		action = Gtk.Action(name = 'PythonDebugger', label = _(u'Python Debugger'),
+				    tooltip = _(u"Enable remote Python debugging with rpdb2"))
 		if have_rpdb2:
 			action.connect('activate', self.enable_debugging)
 		else:
@@ -113,11 +113,11 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 			                                     destroy_cb = self.destroy_console)
 
 			console.set_size_request(600, 400)
-			console.eval('print "%s" %% totem_object' % _("You can access the Totem.Object through " \
+			console.eval('print "%s" %% totem_object' % _(u"You can access the Totem.Object through " \
 				     "\'totem_object\' :\\n%s"), False)
 
 			self.window = Gtk.Window()
-			self.window.set_title(_('Totem Python Console'))
+			self.window.set_title(_(u'Totem Python Console'))
 			self.window.add(console)
 			self.window.connect('destroy', self.destroy_console)
 			self.window.show_all()
@@ -126,7 +126,7 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 			self.window.grab_focus()
 
 	def enable_debugging(self, action):
-		msg = _("After you press OK, Totem will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in DConf, it will use the default password ('totem').")
+		msg = _(u"After you press OK, Totem will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in DConf, it will use the default password ('totem').")
 		dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK_CANCEL, msg)
 		if dialog.run() == Gtk.ResponseType.OK:
 			settings = Gio.Settings.new ('org.gnome.totem.plugins.pythonconsole')



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