From dd98aa44a5084f0590645f5ee9565ab962e6c844 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 10 May 2015 10:37:00 +0200 Subject: =?UTF-8?q?Remove=20gettext=20support,=20as=20we=20don=E2=80=99t?= =?UTF-8?q?=20want=20to=20translate=20poezio,=20and=20it=20takes=20more=20?= =?UTF-8?q?than=201ms=20per=20call.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/commands.py | 69 ++++++----- src/core/core.py | 321 +++++++++++++++++++++++++-------------------------- src/core/handlers.py | 57 +++++---- src/core/structs.py | 51 ++++---- 4 files changed, 247 insertions(+), 251 deletions(-) (limited to 'src/core') diff --git a/src/core/commands.py b/src/core/commands.py index d3bf8023..3830d72a 100644 --- a/src/core/commands.py +++ b/src/core/commands.py @@ -8,7 +8,6 @@ log = logging.getLogger(__name__) import os from datetime import datetime -from gettext import gettext as _ from xml.etree import cElementTree as ET from slixmpp.xmlstream.stanzabase import StanzaBase @@ -65,7 +64,7 @@ def command_help(self, args): buff.extend(acc) msg = '\n'.join(buff) - msg += _("\nType /help to know what each command does") + msg += "\nType /help to know what each command does" else: command = args[0].lstrip('/').strip() @@ -74,10 +73,10 @@ def command_help(self, args): elif command in self.commands: tup = self.commands[command] else: - self.information(_('Unknown command: %s') % command, 'Error') + self.information('Unknown command: %s' % command, 'Error') return if isinstance(tup, Command): - msg = _('Usage: /%s %s\n' % (command, tup.usage)) + msg = 'Usage: /%s %s\n' % (command, tup.usage) msg += tup.desc else: msg = tup[1] @@ -155,7 +154,7 @@ def command_presence(self, args): self.events.trigger('send_normal_presence', pres) pres.send() except: - self.information(_('Could not send directed presence'), 'Error') + self.information('Could not send directed presence', 'Error') log.debug('Could not send directed presence to %s', jid, exc_info=True) return tab = self.get_tab_by_name(jid) @@ -286,14 +285,14 @@ def command_version(self, args): def callback(res): "Callback for /version" if not res: - return self.information(_('Could not get the software' - ' version from %s') % jid, - _('Warning')) - version = _('%s is running %s version %s on %s') % ( + return self.information('Could not get the software' + ' version from %s' % jid, + 'Warning') + version = '%s is running %s version %s on %s' % ( jid, - res.get('name') or _('an unknown software'), - res.get('version') or _('unknown'), - res.get('os') or _('an unknown platform')) + res.get('name') or 'an unknown software', + res.get('version') or 'unknown', + res.get('os') or 'an unknown platform') self.information(version, 'Info') if args is None: @@ -522,9 +521,9 @@ def command_remove_bookmark(self, args): def cb(success): if success: - self.information(_('Bookmark deleted'), 'Info') + self.information('Bookmark deleted', 'Info') else: - self.information(_('Error while deleting the bookmark'), 'Error') + self.information('Error while deleting the bookmark', 'Error') if not args: tab = self.current_tab() @@ -532,13 +531,13 @@ def command_remove_bookmark(self, args): self.bookmarks.remove(tab.name) self.bookmarks.save(self.xmpp, callback=cb) else: - self.information(_('No bookmark to remove'), 'Info') + self.information('No bookmark to remove', 'Info') else: if self.bookmarks[args[0]]: self.bookmarks.remove(args[0]) self.bookmarks.save(self.xmpp, callback=cb) else: - self.information(_('No bookmark to remove'), 'Info') + self.information('No bookmark to remove', 'Info') @command_args_parser.quoted(0, 3) def command_set(self, args): @@ -610,8 +609,8 @@ def command_set(self, args): if args[0] == '.': name = safeJID(self.current_tab().name).bare if not name: - self.information(_('Invalid tab to use the "." argument.'), - _('Error')) + self.information('Invalid tab to use the "." argument.', + 'Error') return section = name else: @@ -672,7 +671,7 @@ def command_server_cycle(self, args): if isinstance(tab, tabs.MucTab): domain = safeJID(tab.name).domain else: - return self.information(_("No server specified"), "Error") + return self.information("No server specified", "Error") for tab in self.get_tabs(tabs.MucTab): if tab.name.endswith(domain): if tab.joined: @@ -695,11 +694,11 @@ def command_last_activity(self, args): "Callback for the last activity" if iq['type'] != 'result': if iq['error']['type'] == 'auth': - self.information(_('You are not allowed to see the ' - 'activity of this contact.'), - _('Error')) + self.information('You are not allowed to see the ' + 'activity of this contact.', + 'Error') else: - self.information(_('Error retrieving the activity'), 'Error') + self.information('Error retrieving the activity', 'Error') return seconds = iq['last_activity']['seconds'] status = iq['last_activity']['status'] @@ -731,9 +730,9 @@ def command_mood(self, args): mood = args[0] if mood not in pep.MOODS: - return self.information(_('%s is not a correct value for a mood.') + return self.information('%s is not a correct value for a mood.' % mood, - _('Error')) + 'Error') if len(args) == 2: text = args[1] else: @@ -752,9 +751,9 @@ def command_activity(self, args): general = args[0] if general not in pep.ACTIVITIES: - return self.information(_('%s is not a correct value for an activity') + return self.information('%s is not a correct value for an activity' % general, - _('Error')) + 'Error') specific = None text = None if length == 2: @@ -766,9 +765,9 @@ def command_activity(self, args): specific = args[1] text = args[2] if specific and specific not in pep.ACTIVITIES[general]: - return self.information(_('%s is not a correct value ' - 'for an activity') % specific, - _('Error')) + return self.information('%s is not a correct value ' + 'for an activity' % specific, + 'Error') self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text, callback=dumb_callback) @@ -862,7 +861,7 @@ def command_destroy_room(self, args): elif isinstance(self.current_tab(), tabs.MucTab) and not args[0]: muc.destroy_room(self.xmpp, self.current_tab().general_jid) else: - self.information(_('Invalid JID: "%s"') % args[0], _('Error')) + self.information('Invalid JID: "%s"' % args[0], 'Error') @command_args_parser.quoted(1, 1, ['']) def command_bind(self, args): @@ -873,7 +872,7 @@ def command_bind(self, args): return self.command_help('bind') if not config.silent_set(args[0], args[1], section='bindings'): - self.information(_('Unable to write in the config file'), 'Error') + self.information('Unable to write in the config file', 'Error') if args[1]: self.information('%s is now bound to %s' % (args[0], args[1]), 'Info') @@ -913,7 +912,7 @@ def command_rawxml(self, args): stanza.send() except: - self.information(_('Could not send custom stanza'), 'Error') + self.information('Could not send custom stanza', 'Error') log.debug('/rawxml: Could not send custom stanza (%s)', repr(stanza), exc_info=True) @@ -941,9 +940,9 @@ def command_plugins(self): """ /plugins """ - self.information(_("Plugins currently in use: %s") % + self.information("Plugins currently in use: %s" % repr(list(self.plugin_manager.plugins.keys())), - _('Info')) + 'Info') @command_args_parser.quoted(1, 1) def command_message(self, args): diff --git a/src/core/core.py b/src/core/core.py index e5a6a970..92c9f987 100644 --- a/src/core/core.py +++ b/src/core/core.py @@ -17,7 +17,6 @@ import pipes import sys import time from threading import Event -from gettext import gettext as _ from slixmpp.xmlstream.handler import Callback @@ -509,15 +508,15 @@ class Core(object): default_tab = tabs.RosterInfoTab() default_tab.on_gain_focus() self.tabs.append(default_tab) - self.information(_('Welcome to poezio!'), _('Info')) + self.information('Welcome to poezio!', 'Info') if firstrun: - self.information(_( + self.information( 'It seems that it is the first time you start poezio.\n' 'The online help is here http://doc.poez.io/\n' 'No room is joined by default, but you can join poezio’s' 'chatroom (with /join poezio@muc.poez.io), where you can' - ' ask for help or tell us how great it is.'), - _('Help')) + ' ask for help or tell us how great it is.', + 'Help') self.refresh_window() self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid) @@ -650,9 +649,9 @@ class Core(object): self.information_win_size, 'var') if not ok: - self.information(_('Unable to save runtime preferences' - ' in the config file'), - _('Error')) + self.information('Unable to save runtime preferences' + ' in the config file', + 'Error') def on_roster_enter_key(self, roster_row): """ @@ -708,8 +707,8 @@ class Core(object): func(arg) return else: - self.information(_("Unknown command (%s)") % (command), - _('Error')) + self.information("Unknown command (%s)" % (command), + 'Error') def exec_command(self, command): """ @@ -842,8 +841,8 @@ class Core(object): msg = msg.replace('\n', '|') if msg else '' ok = ok and config.silent_set('status_message', msg) if not ok: - self.information(_('Unable to save the status in ' - 'the config file'), 'Error') + self.information('Unable to save the status in ' + 'the config file', 'Error') def get_bookmark_nickname(self, room_name): """ @@ -917,18 +916,18 @@ class Core(object): if code in DEPRECATED_ERRORS: body = DEPRECATED_ERRORS[code] else: - body = condition or _('Unknown error') + body = condition or 'Unknown error' else: if code in ERROR_AND_STATUS_CODES: body = ERROR_AND_STATUS_CODES[code] else: - body = condition or _('Unknown error') + body = condition or 'Unknown error' if code: - message = _('%(from)s: %(code)s - %(msg)s: %(body)s') % { - 'from': sender, 'msg': msg, 'body': body, 'code': code} + message = '%(from)s: %(code)s - %(msg)s: %(body)s' % { + 'from': sender, 'msg': msg, 'body': body, 'code': code} else: - message = _('%(from)s: %(msg)s: %(body)s') % { - 'from': sender, 'msg': msg, 'body': body} + message = '%(from)s: %(msg)s: %(body)s' % { + 'from': sender, 'msg': msg, 'body': body} return message @@ -1295,7 +1294,7 @@ class Core(object): Disable private tabs when leaving a room """ if reason is None: - reason = _('\x195}You left the chatroom\x193}') + reason = '\x195}You left the chatroom\x193}' for tab in self.get_tabs(tabs.PrivateTab): if tab.name.startswith(room_name): tab.deactivate(reason=reason) @@ -1305,7 +1304,7 @@ class Core(object): Enable private tabs when joining a room """ if reason is None: - reason = _('\x195}You joined the chatroom\x193}') + reason = '\x195}You joined the chatroom\x193}' for tab in self.get_tabs(tabs.PrivateTab): if tab.name.startswith(room_name): tab.activate(reason=reason) @@ -1594,7 +1593,7 @@ class Core(object): """ enabled = config.get('enable_vertical_tab_list') if not config.silent_set('enable_vertical_tab_list', str(not enabled)): - self.information(_('Unable to write in the config file'), 'Error') + self.information('Unable to write in the config file', 'Error') self.call_for_resize() def resize_global_information_win(self): @@ -1719,225 +1718,225 @@ class Core(object): Register the commands when poezio starts """ self.register_command('help', self.command_help, - usage=_('[command]'), + usage='[command]', shortdesc='\\_o< KOIN KOIN KOIN', completion=self.completion_help) self.register_command('join', self.command_join, - usage=_("[room_name][@server][/nick] [password]"), - desc=_("Join the specified room. You can specify a nickname " - "after a slash (/). If no nickname is specified, you will" - " use the default_nick in the configuration file. You can" - " omit the room name: you will then join the room you\'re" - " looking at (useful if you were kicked). You can also " - "provide a room_name without specifying a server, the " - "server of the room you're currently in will be used. You" - " can also provide a password to join the room.\nExamples" - ":\n/join room@server.tld\n/join room@server.tld/John\n" - "/join room2\n/join /me_again\n/join\n/join room@server" - ".tld/my_nick password\n/join / password"), - shortdesc=_('Join a room'), + usage="[room_name][@server][/nick] [password]", + desc="Join the specified room. You can specify a nickname " + "after a slash (/). If no nickname is specified, you will" + " use the default_nick in the configuration file. You can" + " omit the room name: you will then join the room you\'re" + " looking at (useful if you were kicked). You can also " + "provide a room_name without specifying a server, the " + "server of the room you're currently in will be used. You" + " can also provide a password to join the room.\nExamples" + ":\n/join room@server.tld\n/join room@server.tld/John\n" + "/join room2\n/join /me_again\n/join\n/join room@server" + ".tld/my_nick password\n/join / password", + shortdesc='Join a room', completion=self.completion_join) self.register_command('exit', self.command_quit, - desc=_('Just disconnect from the server and exit poezio.'), - shortdesc=_('Exit poezio.')) + desc='Just disconnect from the server and exit poezio.', + shortdesc='Exit poezio.') self.register_command('quit', self.command_quit, - desc=_('Just disconnect from the server and exit poezio.'), - shortdesc=_('Exit poezio.')) + desc='Just disconnect from the server and exit poezio.', + shortdesc='Exit poezio.') self.register_command('next', self.rotate_rooms_right, - shortdesc=_('Go to the next room.')) + shortdesc='Go to the next room.') self.register_command('prev', self.rotate_rooms_left, - shortdesc=_('Go to the previous room.')) + shortdesc='Go to the previous room.') self.register_command('win', self.command_win, - usage=_(''), - shortdesc=_('Go to the specified room'), + usage='', + shortdesc='Go to the specified room', completion=self.completion_win) self.commands['w'] = self.commands['win'] self.register_command('move_tab', self.command_move_tab, - usage=_(' '), - desc=_("Insert the tab at the position of " - ". This will make the following tabs shift in" - " some cases (refer to the documentation). A tab can be " - "designated by its number or by the beginning of its " - "address. You can use \".\" as a shortcut for the current " - "tab."), - shortdesc=_('Move a tab.'), + usage=' ', + desc="Insert the tab at the position of " + ". This will make the following tabs shift in" + " some cases (refer to the documentation). A tab can be " + "designated by its number or by the beginning of its " + "address. You can use \".\" as a shortcut for the current " + "tab.", + shortdesc='Move a tab.', completion=self.completion_move_tab) self.register_command('destroy_room', self.command_destroy_room, - usage=_('[room JID]'), - desc=_('Try to destroy the room [room JID], or the current' - ' tab if it is a multi-user chat and [room JID] is ' - 'not given.'), - shortdesc=_('Destroy a room.'), + usage='[room JID]', + desc='Try to destroy the room [room JID], or the current' + ' tab if it is a multi-user chat and [room JID] is ' + 'not given.', + shortdesc='Destroy a room.', completion=None) self.register_command('show', self.command_status, - usage=_(' [status message]'), - desc=_("Sets your availability and (optionally) your status " - "message. The argument is one of \"available" - ", chat, away, afk, dnd, busy, xa\" and the optional " - "[status message] argument will be your status message."), - shortdesc=_('Change your availability.'), + usage=' [status message]', + desc="Sets your availability and (optionally) your status " + "message. The argument is one of \"available" + ", chat, away, afk, dnd, busy, xa\" and the optional " + "[status message] argument will be your status message.", + shortdesc='Change your availability.', completion=self.completion_status) self.commands['status'] = self.commands['show'] self.register_command('bookmark_local', self.command_bookmark_local, - usage=_("[roomname][/nick] [password]"), - desc=_("Bookmark Local: Bookmark locally the specified room " - "(you will then auto-join it on each poezio start). This" - " commands uses almost the same syntaxe as /join. Type " - "/help join for syntax examples. Note that when typing " - "\"/bookmark\" on its own, the room will be bookmarked " - "with the nickname you\'re currently using in this room " - "(instead of default_nick)"), - shortdesc=_('Bookmark a room locally.'), + usage="[roomname][/nick] [password]", + desc="Bookmark Local: Bookmark locally the specified room " + "(you will then auto-join it on each poezio start). This" + " commands uses almost the same syntaxe as /join. Type " + "/help join for syntax examples. Note that when typing " + "\"/bookmark\" on its own, the room will be bookmarked " + "with the nickname you\'re currently using in this room " + "(instead of default_nick)", + shortdesc='Bookmark a room locally.', completion=self.completion_bookmark_local) self.register_command('bookmark', self.command_bookmark, - usage=_("[roomname][/nick] [autojoin] [password]"), - desc=_("Bookmark: Bookmark online the specified room (you " - "will then auto-join it on each poezio start if autojoin" - " is specified and is 'true'). This commands uses almost" - " the same syntax as /join. Type /help join for syntax " - "examples. Note that when typing \"/bookmark\" alone, the" - " room will be bookmarked with the nickname you\'re " - "currently using in this room (instead of default_nick)."), - shortdesc=_("Bookmark a room online."), + usage="[roomname][/nick] [autojoin] [password]", + desc="Bookmark: Bookmark online the specified room (you " + "will then auto-join it on each poezio start if autojoin" + " is specified and is 'true'). This commands uses almost" + " the same syntax as /join. Type /help join for syntax " + "examples. Note that when typing \"/bookmark\" alone, the" + " room will be bookmarked with the nickname you\'re " + "currently using in this room (instead of default_nick).", + shortdesc="Bookmark a room online.", completion=self.completion_bookmark) self.register_command('set', self.command_set, - usage=_("[plugin|][section]