Browse Source

marked pygtk and mitter for translations

master
Julio Biason 15 years ago
parent
commit
31bd1cfec9
  1. 13
      mitter
  2. 143
      mitterlib/ui/ui_pygtk.py

13
mitter

@ -22,6 +22,7 @@ import urllib
import os import os
import logging import logging
import warnings import warnings
import gettext
import mitterlib.network as network import mitterlib.network as network
@ -31,6 +32,12 @@ from mitterlib.ui import Interfaces
log = logging.getLogger('mitter') log = logging.getLogger('mitter')
# ----------------------------------------------------------------------
# i18n stuff
# ----------------------------------------------------------------------
gettext.bindtextdomain('mitter')
gettext.textdomain('mitter')
_ = gettext.gettext
def main(): def main():
"""Main function.""" """Main function."""
@ -43,7 +50,7 @@ def main():
group='General', group='General',
option='debug', option='debug',
action='store_true', action='store_true',
help='Display debugging information.', help=_('Display debugging information.'),
default=False, default=False,
is_config_option=False) is_config_option=False)
options.add_option('-i', '--interface', options.add_option('-i', '--interface',
@ -51,7 +58,7 @@ def main():
option='interface', option='interface',
default=None, default=None,
metavar='INTERFACE', metavar='INTERFACE',
help='Interface to be used.') help=_('Interface to be used.'))
# Start the network manager (which will add the network options) # Start the network manager (which will add the network options)
connection = Networks(options) connection = Networks(options)
@ -88,7 +95,7 @@ def main():
# they don't chose anything.) # they don't chose anything.)
display = interfaces.load(connection, preferred_interface) display = interfaces.load(connection, preferred_interface)
if display is None: if display is None:
log.error('Sorry, no interface could be found for your system') log.error(_('Sorry, no interface could be found for your system'))
return return
# display the interface (the interface should take care of updating # display the interface (the interface should take care of updating

143
mitterlib/ui/ui_pygtk.py

@ -45,8 +45,8 @@ URL_RE = re.compile(r'(https?://[^\s\n\r]+)', re.I)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# I18n bits # I18n bits
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
#t = gettext.translation('ui_pygtk') t = gettext.translation('ui_pygtk', fallback=True)
#_ = t.gettext _ = t.gettext
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# String with the format to the message # String with the format to the message
@ -381,97 +381,97 @@ class Interface(object):
# Actions related to the UI elements above # Actions related to the UI elements above
# Top-level menu actions # Top-level menu actions
file_action = gtk.Action('File', '_File', 'File', None) file_action = gtk.Action('File', _('_File'), _('File'), None)
action_group.add_action(file_action) action_group.add_action(file_action)
edit_action = gtk.Action('Edit', '_Edit', 'Edit', None) edit_action = gtk.Action('Edit', _('_Edit'), _('Edit'), None)
action_group.add_action(edit_action) action_group.add_action(edit_action)
message_action = gtk.Action('Message', '_Message', message_action = gtk.Action('Message', _('_Message'),
'Message related options', None) _('Message related options'), None)
action_group.add_action(message_action) action_group.add_action(message_action)
view_action = gtk.Action('View', '_View', 'View', None) view_action = gtk.Action('View', _('_View'), _('View'), None)
action_group.add_action(view_action) action_group.add_action(view_action)
help_action = gtk.Action('Help', '_Help', 'Help', None) help_action = gtk.Action('Help', _('_Help'), _('Help'), None)
action_group.add_action(help_action) action_group.add_action(help_action)
# File actions # File actions
quit_action = gtk.Action('Quit', '_Quit', quit_action = gtk.Action('Quit', _('_Quit'),
'Exit Mitter', gtk.STOCK_QUIT) _('Exit Mitter'), gtk.STOCK_QUIT)
quit_action.connect('activate', self._quit_app) quit_action.connect('activate', self._quit_app)
action_group.add_action_with_accel(quit_action, None) action_group.add_action_with_accel(quit_action, None)
# Edit actions # Edit actions
refresh_action = gtk.Action('Refresh', '_Refresh', refresh_action = gtk.Action('Refresh', _('_Refresh'),
'Update the listing', gtk.STOCK_REFRESH) _('Update the listing'), gtk.STOCK_REFRESH)
refresh_action.connect('activate', self._refresh) refresh_action.connect('activate', self._refresh)
action_group.add_action_with_accel(refresh_action, None) action_group.add_action_with_accel(refresh_action, None)
self._update_action = gtk.Action('Update', '_Update', self._update_action = gtk.Action('Update', _('_Update'),
'Update your status', gtk.STOCK_ADD) _('Update your status'), gtk.STOCK_ADD)
self._update_action.set_property('sensitive', False) self._update_action.set_property('sensitive', False)
self._update_action.connect('activate', self._update_status) self._update_action.connect('activate', self._update_status)
action_group.add_action_with_accel(self._update_action, action_group.add_action_with_accel(self._update_action,
'Return') 'Return')
self._cancel_action = gtk.Action('Cancel', '_Cancel', self._cancel_action = gtk.Action('Cancel', _('_Cancel'),
'Cancel the update', gtk.STOCK_CANCEL) _('Cancel the update'), gtk.STOCK_CANCEL)
self._cancel_action.connect('activate', self._clear_text) self._cancel_action.connect('activate', self._clear_text)
action_group.add_action_with_accel(self._cancel_action, action_group.add_action_with_accel(self._cancel_action,
'Escape') 'Escape')
clear_action = gtk.Action('Clear', '_Clear', clear_action = gtk.Action('Clear', _('_Clear'),
'Clear the message list', gtk.STOCK_CLEAR) _('Clear the message list'), gtk.STOCK_CLEAR)
clear_action.connect('activate', self._clear_posts) clear_action.connect('activate', self._clear_posts)
action_group.add_action_with_accel(clear_action, '<Ctrl>l') action_group.add_action_with_accel(clear_action, '<Ctrl>l')
settings_action = gtk.Action('Settings', '_Settings', settings_action = gtk.Action('Settings', _('_Settings'),
'Settings', gtk.STOCK_PREFERENCES) _('Settings'), gtk.STOCK_PREFERENCES)
settings_action.connect('activate', self._show_settings) settings_action.connect('activate', self._show_settings)
action_group.add_action(settings_action) action_group.add_action(settings_action)
# Message actions # Message actions
self._delete_action = gtk.Action('Delete', '_Delete', self._delete_action = gtk.Action('Delete', _('_Delete'),
'Delete a post', gtk.STOCK_DELETE) _('Delete a post'), gtk.STOCK_DELETE)
self._delete_action.set_property('sensitive', False) self._delete_action.set_property('sensitive', False)
self._delete_action.connect('activate', self._delete_message) self._delete_action.connect('activate', self._delete_message)
action_group.add_action_with_accel(self._delete_action, 'Delete') action_group.add_action_with_accel(self._delete_action, 'Delete')
self._reply_action = gtk.Action('Reply', '_Reply', self._reply_action = gtk.Action('Reply', _('_Reply'),
"Send a response to someone's else message", gtk.STOCK_REDO) _("Send a response to someone's else message"), gtk.STOCK_REDO)
self._reply_action.set_property('sensitive', False) self._reply_action.set_property('sensitive', False)
self._reply_action.connect('activate', self._reply_message) self._reply_action.connect('activate', self._reply_message)
action_group.add_action_with_accel(self._reply_action, '<Ctrl>r') action_group.add_action_with_accel(self._reply_action, '<Ctrl>r')
self._repost_action = gtk.Action('Repost', 'Re_post', self._repost_action = gtk.Action('Repost', _('Re_post'),
"Put someone's else message on your timeline", _("Put someone's else message on your timeline"),
gtk.STOCK_CONVERT) gtk.STOCK_CONVERT)
self._repost_action.set_property('sensitive', False) self._repost_action.set_property('sensitive', False)
self._repost_action.connect('activate', self._repost_message) self._repost_action.connect('activate', self._repost_message)
action_group.add_action_with_accel(self._repost_action, '<Ctrl>p') action_group.add_action_with_accel(self._repost_action, '<Ctrl>p')
self._favourite_action = gtk.Action('Favourite', '_Favourite', self._favourite_action = gtk.Action('Favourite', _('_Favourite'),
'Toggle the favourite status of a message', _('Toggle the favourite status of a message'),
gtk.STOCK_ABOUT) gtk.STOCK_ABOUT)
self._favourite_action.set_property('sensitive', False) self._favourite_action.set_property('sensitive', False)
self._favourite_action.connect('activate', self._favourite_message) self._favourite_action.connect('activate', self._favourite_message)
action_group.add_action_with_accel(self._favourite_action, '<Ctrl>f') action_group.add_action_with_accel(self._favourite_action, '<Ctrl>f')
# view actions # view actions
view_messages_action = gtk.Action('Messages', '_Messages', view_messages_action = gtk.Action('Messages', _('_Messages'),
'Display messages', None) _('Display messages'), None)
view_messages_action.connect('activate', self._change_tab, 0) view_messages_action.connect('activate', self._change_tab, 0)
action_group.add_action_with_accel(view_messages_action, '<Alt>1') action_group.add_action_with_accel(view_messages_action, '<Alt>1')
view_replies_action = gtk.Action('Replies', '_Replies', view_replies_action = gtk.Action('Replies', _('_Replies'),
'Display replies', None) _('Display replies'), None)
view_replies_action.connect('activate', self._change_tab, 1) view_replies_action.connect('activate', self._change_tab, 1)
action_group.add_action_with_accel(view_replies_action, '<Alt>2') action_group.add_action_with_accel(view_replies_action, '<Alt>2')
# Help actions # Help actions
about_action = gtk.Action('About', '_About', 'About Mitter', about_action = gtk.Action('About', _('_About'), _('About Mitter'),
gtk.STOCK_ABOUT) gtk.STOCK_ABOUT)
about_action.connect('activate', self._show_about) about_action.connect('activate', self._show_about)
action_group.add_action(about_action) action_group.add_action(about_action)
@ -542,10 +542,10 @@ class Interface(object):
about_window = gtk.AboutDialog() about_window = gtk.AboutDialog()
about_window.set_name('Mitter') about_window.set_name('Mitter')
about_window.set_version(version) about_window.set_version(version)
about_window.set_copyright('2007-2009 Mitter Contributors') about_window.set_copyright('2007-2010 Mitter Contributors')
about_window.set_license(gpl_3) about_window.set_license(gpl_3)
about_window.set_website('http://code.google.com/p/mitter') about_window.set_website('http://code.google.com/p/mitter')
about_window.set_website_label('Mitter on GoogleCode') about_window.set_website_label(_('Mitter on GoogleCode'))
about_window.set_authors([ about_window.set_authors([
'Main developers:', 'Main developers:',
'Julio Biason', 'Julio Biason',
@ -618,10 +618,11 @@ class Interface(object):
info = [] info = []
if data.reposted_by: if data.reposted_by:
info.append(' &#8212; <i>reposted by %s</i>' % (data.reposted_by)) info.append(_(' &#8212; <i>reposted by %s</i>') %
(data.reposted_by))
if data.parent_owner: if data.parent_owner:
info.append(' &#8212; <i>in reply to %s</i>' % info.append(_(' &#8212; <i>in reply to %s</i>') %
(data.parent_owner)) (data.parent_owner))
message_values['message_type'] = ''.join(info) message_values['message_type'] = ''.join(info)
@ -666,7 +667,7 @@ class Interface(object):
self._refresh_id = None self._refresh_id = None
# do the refresh # do the refresh
self._update_statusbar('Retrieving messages...') self._update_statusbar(_('Retrieving messages...'))
self._threads.add_work(self._post_get_messages, self._threads.add_work(self._post_get_messages,
self._exception_get_messages, self._exception_get_messages,
self._connection.messages) self._connection.messages)
@ -689,7 +690,7 @@ class Interface(object):
link = self._connection.link(message) link = self._connection.link(message)
if link: if link:
network = self._connection.name(message.network) network = self._connection.name(message.network)
items.append(('Open on %s' % (network), link)) items.append((_('Open on %s') % (network), link))
urls = URL_RE.findall(message.message) urls = URL_RE.findall(message.message)
for url in urls: for url in urls:
@ -718,11 +719,11 @@ class Interface(object):
"""Update the elements in the interface that should change in case of """Update the elements in the interface that should change in case of
changes in the message count.""" changes in the message count."""
child = self._main_tabs.get_nth_page(0) child = self._main_tabs.get_nth_page(0)
self._main_tabs.set_tab_label_text(child, 'Messages (%d)' % self._main_tabs.set_tab_label_text(child, _('Messages (%d)') %
(self._new_message_count)) (self._new_message_count))
child = self._main_tabs.get_nth_page(1) child = self._main_tabs.get_nth_page(1)
self._main_tabs.set_tab_label_text(child, 'Replies (%d)' % self._main_tabs.set_tab_label_text(child, _('Replies (%d)') %
(self._new_replies_count)) (self._new_replies_count))
if self._statusicon: if self._statusicon:
@ -797,12 +798,13 @@ class Interface(object):
count = len(text) count = len(text)
if self._reply_message_id: if self._reply_message_id:
suffix = '(replying to %s)' % (self._reply_message_id.username) suffix = _('(replying to %s)') % (self._reply_message_id.username)
else: else:
suffix = '' suffix = ''
# TODO: gettext to properly use "characters"/"character" # TODO: gettext to properly use "characters"/"character"
text = '%d characters %s' % (count, suffix) text = N_('%d character %s', '%d characters %s', count) % (count,
suffix)
self._statusbar.push(self._remove_count_status(), text) self._statusbar.push(self._remove_count_status(), text)
self._update_sensitivity(not (count == 0)) self._update_sensitivity(not (count == 0))
@ -820,7 +822,7 @@ class Interface(object):
_log.debug('Status: %s', status) _log.debug('Status: %s', status)
self._remove_count_status() self._remove_count_status()
self._update_statusbar('Sending update...') self._update_statusbar(_('Sending update...'))
self._update_sensitivity(False) self._update_sensitivity(False)
self._threads.add_work(self._post_update_status, self._threads.add_work(self._post_update_status,
self._exception_update_status, self._exception_update_status,
@ -930,7 +932,7 @@ class Interface(object):
confirm = gtk.MessageDialog(parent=self._main_window, confirm = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_QUESTION, type=gtk.MESSAGE_QUESTION,
message_format='Delete this message?', message_format=_('Delete this message?'),
buttons=gtk.BUTTONS_YES_NO); buttons=gtk.BUTTONS_YES_NO);
option = confirm.run() option = confirm.run()
confirm.hide() confirm.hide()
@ -940,7 +942,7 @@ class Interface(object):
_log.debug("Delete cancelled"); _log.debug("Delete cancelled");
return False return False
self._update_statusbar('Deleting message...') self._update_statusbar(_('Deleting message...'))
self._delete_iter = iter self._delete_iter = iter
_log.debug('Deleting messing %d', message.id) _log.debug('Deleting messing %d', message.id)
self._threads.add_work(self._post_delete_message, self._threads.add_work(self._post_delete_message,
@ -966,7 +968,7 @@ class Interface(object):
grid = self._get_current_grid() grid = self._get_current_grid()
(model, iter) = grid.get_selection().get_selected() (model, iter) = grid.get_selection().get_selected()
message = model.get_value(iter, 0) message = model.get_value(iter, 0)
self._update_statusbar('Reposting %s message...' % self._update_statusbar(_('Reposting %s message...') %
(message.username)) (message.username))
self._threads.add_work(self._post_repost_message, self._threads.add_work(self._post_repost_message,
self._exception_repost_message, self._exception_repost_message,
@ -983,9 +985,9 @@ class Interface(object):
self._favourite_iter = iter self._favourite_iter = iter
if message.favourite: if message.favourite:
display = 'Removing message from %s from favourites...' display = _('Removing message from %s from favourites...')
else: else:
display = 'Marking message from %s as favourite...' display = _('Marking message from %s as favourite...')
self._update_status(display % (message.username)) self._update_status(display % (message.username))
self._threads.add_work(self._post_favourite_message, self._threads.add_work(self._post_favourite_message,
@ -996,7 +998,7 @@ class Interface(object):
def _show_settings(self, widget, user_data=None): def _show_settings(self, widget, user_data=None):
"""Display the settings window.""" """Display the settings window."""
settings_window = gtk.Dialog(title='Settings', settings_window = gtk.Dialog(title=_('Settings'),
parent=self._main_window, parent=self._main_window,
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
buttons=(gtk.STOCK_OK, 0)) buttons=(gtk.STOCK_OK, 0))
@ -1013,12 +1015,12 @@ class Interface(object):
self._refresh_interval_field.set_increments(1, 5) self._refresh_interval_field.set_increments(1, 5)
interface_box = gtk.Table(rows=1, columns=2, homogeneous=False) interface_box = gtk.Table(rows=1, columns=2, homogeneous=False)
interface_box.attach(gtk.Label('Refresh interval (minutes):'), interface_box.attach(gtk.Label(_('Refresh interval (minutes):')),
0, 1, 0, 1) 0, 1, 0, 1)
interface_box.attach(self._refresh_interval_field, 0, 1, 1, 2) interface_box.attach(self._refresh_interval_field, 0, 1, 1, 2)
interface_box.show_all() interface_box.show_all()
tabs.insert_page(interface_box, gtk.Label('Interface')) tabs.insert_page(interface_box, gtk.Label(_('Interface')))
# We store the fields in a dictionary, inside dictionaries for each # We store the fields in a dictionary, inside dictionaries for each
# NAMESPACE. To set the values, we just run the dictionaries setting # NAMESPACE. To set the values, we just run the dictionaries setting
@ -1176,7 +1178,7 @@ class Interface(object):
self._message_count_updated() self._message_count_updated()
# now get replies # now get replies
self._update_statusbar('Retrieving replies...') self._update_statusbar(_('Retrieving replies...'))
self._threads.add_work(self._post_get_replies, self._threads.add_work(self._post_get_replies,
self._exception_get_messages, self._exception_get_messages,
self._connection.replies) self._connection.replies)
@ -1188,13 +1190,13 @@ class Interface(object):
_log.debug(str(exception)) _log.debug(str(exception))
error_win = gtk.MessageDialog(parent=self._main_window, error_win = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_ERROR, type=gtk.MESSAGE_ERROR,
message_format='Error retrieving current messages. ' \ message_format=_('Error retrieving current messages. ' \
'Auto-refresh disabled. Use the "Refresh" option ' \ 'Auto-refresh disabled. Use the "Refresh" option ' \
'to re-enable it.', 'to re-enable it.'),
buttons=gtk.BUTTONS_OK) buttons=gtk.BUTTONS_OK)
error_win.run() error_win.run()
error_win.hide() error_win.hide()
self._update_statusbar('Auto-update disabled') self._update_statusbar(_('Auto-update disabled'))
if self._statusicon: if self._statusicon:
self._statusicon.set_from_pixbuf(self._images['icon-error']) self._statusicon.set_from_pixbuf(self._images['icon-error'])
return return
@ -1216,8 +1218,8 @@ class Interface(object):
interval = self._options[self.NAMESPACE]['refresh_interval'] interval = self._options[self.NAMESPACE]['refresh_interval']
_log.debug('Queueing next refresh in %d minutes', interval) _log.debug('Queueing next refresh in %d minutes', interval)
self._update_statusbar('New messages retrieved. Next update in ' \ self._update_statusbar(_('New messages retrieved. Next update in ' \
'%d minutes.' % (interval)) '%d minutes.') % (interval))
self._refresh_id = gobject.timeout_add( self._refresh_id = gobject.timeout_add(
interval * 60 * 1000, interval * 60 * 1000,
self._refresh, None) self._refresh, None)
@ -1260,7 +1262,7 @@ class Interface(object):
### Results for the update status call ### Results for the update status call
def _post_update_status(self, widget, data): def _post_update_status(self, widget, data):
"""Called when the status is updated correctly.""" """Called when the status is updated correctly."""
self._update_statusbar('Your status was updated.') self._update_statusbar(_('Your status was updated.'))
self._update_sensitivity(False) self._update_sensitivity(False)
self._clear_text(None) self._clear_text(None)
return return
@ -1272,8 +1274,8 @@ class Interface(object):
_log.debug(str(exception)) _log.debug(str(exception))
error_win = gtk.MessageDialog(parent=self._main_window, error_win = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_ERROR, type=gtk.MESSAGE_ERROR,
message_format='Error updating your status. Please ' \ message_format=_('Error updating your status. Please ' \
'try again.', 'try again.'),
buttons=gtk.BUTTONS_OK) buttons=gtk.BUTTONS_OK)
error_win.run() error_win.run()
error_win.hide() error_win.hide()
@ -1286,7 +1288,7 @@ class Interface(object):
if self._delete_iter: if self._delete_iter:
self._grid.get_model().remove(self._delete_iter) self._grid.get_model().remove(self._delete_iter)
self._delete_iter = None self._delete_iter = None
self._update_statusbar('Message deleted.') self._update_statusbar(_('Message deleted.'))
return return
def _exception_delete_message(self, widget, exception): def _exception_delete_message(self, widget, exception):
@ -1299,7 +1301,7 @@ class Interface(object):
def _post_repost_message(self, widget, data): def _post_repost_message(self, widget, data):
"""Called when the message is reposted successfully.""" """Called when the message is reposted successfully."""
_log.debug('Repost successful') _log.debug('Repost successful')
self._update_statusbar('Message reposted') self._update_statusbar(_('Message reposted'))
return return
def _exception_repost_message(self, widget, exception): def _exception_repost_message(self, widget, exception):
@ -1309,8 +1311,8 @@ class Interface(object):
error_win = gtk.MessageDialog(parent=self._main_window, error_win = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_ERROR, type=gtk.MESSAGE_ERROR,
message_format='Error reposting message. Please ' \ message_format=_('Error reposting message. Please ' \
'try again.', 'try again.'),
buttons=gtk.BUTTONS_OK) buttons=gtk.BUTTONS_OK)
error_win.run() error_win.run()
error_win.hide() error_win.hide()
@ -1322,9 +1324,9 @@ class Interface(object):
_log.debug('Favourite status changed.') _log.debug('Favourite status changed.')
message = self._grid.get_model().get_value(self._favourite_iter, 0) message = self._grid.get_model().get_value(self._favourite_iter, 0)
if message.favourite: if message.favourite:
display = 'Message unfavourited.' display = _('Message unfavourited.')
else: else:
display = 'Message favourited.' display = _('Message favourited.')
self._update_statusbar(display) self._update_statusbar(display)
message.favourite = not message.favourite message.favourite = not message.favourite
self._favourite_iter = None self._favourite_iter = None
@ -1337,8 +1339,8 @@ class Interface(object):
error_win = gtk.MessageDialog(parent=self._main_window, error_win = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_ERROR, type=gtk.MESSAGE_ERROR,
message_format='Error changing favourite status of the ' \ message_format=_('Error changing favourite status of the ' \
'message. Please, try again.', 'message. Please, try again.'),
buttons=gtk.BUTTONS_OK) buttons=gtk.BUTTONS_OK)
error_win.run() error_win.run()
error_win.hide() error_win.hide()
@ -1413,7 +1415,7 @@ class Interface(object):
options.add_option('--refresh-interval', options.add_option('--refresh-interval',
group=self.NAMESPACE, group=self.NAMESPACE,
option='refresh_interval', option='refresh_interval',
help='Refresh interval', help=_('Refresh interval.'),
type='int', type='int',
metavar='MINUTES', metavar='MINUTES',
default=5, default=5,
@ -1422,6 +1424,7 @@ class Interface(object):
group=self.NAMESPACE, group=self.NAMESPACE,
action='store_false', action='store_false',
option='statusicon', option='statusicon',
help=_('Disable the use of the status icon.'),
default=True, default=True,
conflict_group='interface') conflict_group='interface')
# Most of the options for non-cmd-options are useless, but I'm keeping # Most of the options for non-cmd-options are useless, but I'm keeping

Loading…
Cancel
Save