Verified Commit dd98aa44 authored by Link Mauve's avatar Link Mauve Committed by mathieui

Remove gettext support, as we don’t want to translate poezio, and it takes more than 1ms per call.

parent 861f5c4b
......@@ -3,7 +3,6 @@ Module related to the argument parsing
There is a fallback to the deprecated optparse if argparse is not found
"""
from gettext import gettext as _
from os import path
from argparse import ArgumentParser, SUPPRESS
......@@ -14,13 +13,13 @@ def parse_args(CONFIG_PATH=''):
parser = ArgumentParser('poezio')
parser.add_argument("-c", "--check-config", dest="check_config",
action='store_true',
help=_('Check the config file'))
help='Check the config file')
parser.add_argument("-d", "--debug", dest="debug",
help=_("The file where debug will be written"),
help="The file where debug will be written",
metavar="DEBUG_FILE")
parser.add_argument("-f", "--file", dest="filename",
default=path.join(CONFIG_PATH, 'poezio.cfg'),
help=_("The config file you want to use"),
help="The config file you want to use",
metavar="CONFIG_FILE")
parser.add_argument("-v", "--version", dest="version",
help=SUPPRESS, metavar="VERSION",
......
......@@ -30,7 +30,6 @@ Adding a remote bookmark:
import functools
import logging
from gettext import gettext as _
from slixmpp.plugins.xep_0048 import Bookmarks, Conference, URL
from slixmpp import JID
......@@ -245,7 +244,7 @@ class BookmarkList(object):
"""Add the remotely stored bookmarks to the list."""
force = config.get('force_remote_bookmarks')
if xmpp.anon or not (any(self.available_storage.values()) or force):
information(_('No remote bookmark storage available'), 'Warning')
information('No remote bookmark storage available', 'Warning')
return
if force and not any(self.available_storage.values()):
......@@ -256,7 +255,7 @@ class BookmarkList(object):
self.available_storage[method] = True
old_callback(result)
else:
information(_('No remote bookmark storage available'), 'Warning')
information('No remote bookmark storage available', 'Warning')
callback = new_callback
if self.preferred == 'pep':
......
......@@ -16,7 +16,6 @@ import logging.config
import os
import sys
import pkg_resources
from gettext import gettext as _
from configparser import RawConfigParser, NoOptionError, NoSectionError
from os import environ, makedirs, path, remove
......@@ -410,9 +409,9 @@ class Config(RawConfigParser):
elif current.lower() == "true":
value = "false"
else:
return (_('Could not toggle option: %s.'
' Current value is %s.') %
(option, current or _("empty")),
return ('Could not toggle option: %s.'
' Current value is %s.' %
(option, current or "empty"),
'Warning')
if self.has_section(section):
RawConfigParser.set(self, section, option, value)
......@@ -420,7 +419,7 @@ class Config(RawConfigParser):
self.add_section(section)
RawConfigParser.set(self, section, option, value)
if not self.write_in_file(section, option, value):
return (_('Unable to write in the config file'), 'Error')
return ('Unable to write in the config file', 'Error')
return ("%s=%s" % (option, value), 'Info')
def remove_and_save(self, option, section=DEFSECTION):
......@@ -430,8 +429,8 @@ class Config(RawConfigParser):
if self.has_section(section):
RawConfigParser.remove_option(self, section, option)
if not self.remove_in_file(section, option):
return (_('Unable to save the config file'), 'Error')
return (_('Option %s deleted') % option, 'Info')
return ('Unable to save the config file', 'Error')
return ('Option %s deleted' % option, 'Info')
def silent_set(self, option, value, section=DEFSECTION):
"""
......
......@@ -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 <command_name> to know what each command does")
msg += "\nType /help <command_name> 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):
......
This diff is collapsed.
......@@ -12,7 +12,6 @@ import ssl
import sys
import time
from hashlib import sha1, sha512
from gettext import gettext as _
from os import path
from slixmpp import InvalidJID
......@@ -80,8 +79,8 @@ def check_bookmark_storage(self, features):
type_ = iq['error']['type']
condition = iq['error']['condition']
if not (type_ == 'cancel' and condition == 'item-not-found'):
self.information(_('Unable to fetch the remote'
' bookmarks; %s: %s') % (type_, condition),
self.information('Unable to fetch the remote'
' bookmarks; %s: %s' % (type_, condition),
'Error')
return
remote_bookmarks = self.bookmarks.remote()
......@@ -245,7 +244,7 @@ def on_error_message(self, message):
tab = self.get_conversation_by_jid(message['from'], create=False)
error_msg = self.get_error_message(message, deprecated=True)
if not tab:
return self.information(error_msg, _('Error'))
return self.information(error_msg, 'Error')
error = '\x19%s}%s\x19o' % (dump_tuple(get_theme().COLOR_CHAR_NACK),
error_msg)
if not tab.nack_message('\n' + error, message['id'], message['to']):
......@@ -522,7 +521,7 @@ def on_groupchat_message(self, message):
tab = self.get_tab_by_name(room_from, tabs.MucTab)
if not tab:
self.information(_("message received for a non-existing room: %s") % (room_from))
self.information("message received for a non-existing room: %s" % (room_from))
muc.leave_groupchat(self.xmpp, room_from, self.own_nick, msg='')
return
......@@ -763,10 +762,10 @@ def on_subscription_request(self, presence):
contact = roster.get_and_set(jid)
roster.update_contact_groups(contact)
contact.pending_in = True
self.information(_('%s wants to subscribe to your presence, '
'use /accept <jid> or /deny <jid> to accept '
'or reject the query.') % jid,
'Roster')
self.information('%s wants to subscribe to your presence, '
'use /accept <jid> or /deny <jid> to accept '
'or reject the query.' % jid,
'Roster')
self.get_tab_by_number(0).state = 'highlight'
roster.modified()
if isinstance(self.current_tab(), tabs.RosterInfoTab):
......@@ -859,7 +858,7 @@ def on_got_offline(self, presence):
return
jid = presence['from']
if not logger.log_roster_change(jid.bare, 'got offline'):
self.information(_('Unable to write in the log file'), 'Error')
self.information('Unable to write in the log file', 'Error')
# If a resource got offline, display the message in the conversation with this
# precise resource.
if jid.resource:
......@@ -883,7 +882,7 @@ def on_got_online(self, presence):
return
roster.modified()
if not logger.log_roster_change(jid.bare, 'got online'):
self.information(_('Unable to write in the log file'), 'Error')
self.information('Unable to write in the log file', 'Error')
resource = Resource(jid.full, {
'priority': presence.get_priority() or 0,
'status': presence['status'],
......@@ -920,7 +919,7 @@ def on_failed_connection(self, error):
"""
We cannot contact the remote server
"""
self.information(_("Connection to remote server failed: %s" % (error,)), _('Error'))
self.information("Connection to remote server failed: %s" % (error,), 'Error')
def on_disconnected(self, event):
"""
......@@ -931,10 +930,10 @@ def on_disconnected(self, event):
roster.modified()
for tab in self.get_tabs(tabs.MucTab):
tab.disconnect()
msg_typ = _('Error') if not self.legitimate_disconnect else _('Info')
self.information(_("Disconnected from server."), msg_typ)
msg_typ = 'Error' if not self.legitimate_disconnect else 'Info'
self.information("Disconnected from server.", msg_typ)
if not self.legitimate_disconnect and config.get('auto_reconnect', True):
self.information(_("Auto-reconnecting."), _('Info'))
self.information("Auto-reconnecting.", 'Info')
self.xmpp.connect()
def on_stream_error(self, event):
......@@ -942,29 +941,29 @@ def on_stream_error(self, event):
When we receive a stream error
"""
if event and event['text']:
self.information(_('Stream error: %s') % event['text'], _('Error'))
self.information('Stream error: %s' % event['text'], 'Error')
def on_failed_all_auth(self, event):
"""
Authentication failed
"""
self.information(_("Authentication failed (bad credentials?)."),
_('Error'))
self.information("Authentication failed (bad credentials?).",
'Error')
self.legitimate_disconnect = True
def on_no_auth(self, event):
"""
Authentication failed (no mech)
"""
self.information(_("Authentication failed, no login method available."),
_('Error'))
self.information("Authentication failed, no login method available.",
'Error')
self.legitimate_disconnect = True
def on_connected(self, event):
"""
Remote host responded, but we are not yet authenticated
"""
self.information(_("Connected to server."), 'Info')
self.information("Connected to server.", 'Info')
def on_connecting(self, event):
"""
......@@ -979,8 +978,8 @@ def on_session_start(self, event):
self.connection_time = time.time()
if not self.plugins_autoloaded: # Do not reload plugins on reconnection
self.autoload_plugins()
self.information(_("Authentication success."), 'Info')
self.information(_("Your JID is %s") % self.xmpp.boundjid.full, 'Info')
self.information("Authentication success.", 'Info')
self.information("Your JID is %s" % self.xmpp.boundjid.full, 'Info')
if not self.xmpp.anon:
# request the roster
self.xmpp.get_roster()
......@@ -1075,12 +1074,12 @@ def on_groupchat_subject(self, message):
# Do not display the message if the subject did not change or if we
# receive an empty topic when joining the room.
if nick_from:
tab.add_message(_("\x19%(info_col)s}%(nick)s set the subject to: %(subject)s") %
tab.add_message("\x19%(info_col)s}%(nick)s set the subject to: %(subject)s" %
{'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'nick':nick_from, 'subject':subject},
time=None,
typ=2)
else:
tab.add_message(_("\x19%(info_col)s}The subject is: %(subject)s") %
tab.add_message("\x19%(info_col)s}The subject is: %(subject)s" %
{'subject':subject, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)},
time=None,
typ=2)
......@@ -1144,14 +1143,14 @@ def room_error(self, error, room_name):
nick_color=get_theme().COLOR_ERROR_MSG, typ=2)
code = error['error']['code']
if code == '401':
msg = _('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)')
msg = 'To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)'
tab.add_message(msg, typ=2)
if code == '409':
if config.get('alternative_nickname') != '':
self.command_join('%s/%s'% (tab.name, tab.own_nick+config.get('alternative_nickname')))
else:
if not tab.joined:
tab.add_message(_('You can join the room with an other nick, by typing "/join /other_nick"'), typ=2)
tab.add_message('You can join the room with an other nick, by typing "/join /other_nick"', typ=2)
self.refresh_window()
def outgoing_stanza(self, stanza):
......@@ -1243,7 +1242,7 @@ def validate_ssl(self, pem):
self.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info')
log.debug('Setting certificate to %s', sha2_found_cert)
if not config.silent_set('certificate', sha2_found_cert):
self.information(_('Unable to write in the config file'), 'Error')
self.information('Unable to write in the config file', 'Error')
else:
self.information('You refused to validate the certificate. You are now disconnected', 'Info')
self.disconnect()
......@@ -1263,7 +1262,7 @@ def validate_ssl(self, pem):
else:
log.debug('First time. Setting certificate to %s', sha2_found_cert)
if not config.silent_set('certificate', sha2_found_cert):
self.information(_('Unable to write in the config file'), 'Error')
self.information('Unable to write in the config file', 'Error')
def _composing_tab_state(tab, state):
"""
......
......@@ -2,39 +2,38 @@
Module defining structures useful to the core class and related methods
"""
import collections
from gettext import gettext as _
# http://xmpp.org/extensions/xep-0045.html#errorstatus
ERROR_AND_STATUS_CODES = {
'401': _('A password is required'),
'403': _('Permission denied'),
'404': _('The room doesn’t exist'),
'405': _('Your are not allowed to create a new room'),
'406': _('A reserved nick must be used'),
'407': _('You are not in the member list'),
'409': _('This nickname is already in use or has been reserved'),
'503': _('The maximum number of users has been reached'),
'401': 'A password is required',
'403': 'Permission denied',
'404': 'The room doesn’t exist',
'405': 'Your are not allowed to create a new room',
'406': 'A reserved nick must be used',
'407': 'You are not in the member list',
'409': 'This nickname is already in use or has been reserved',
'503': 'The maximum number of users has been reached',
}
# http://xmpp.org/extensions/xep-0086.html
DEPRECATED_ERRORS = {
'302': _('Redirect'),
'400': _('Bad request'),
'401': _('Not authorized'),
'402': _('Payment required'),
'403': _('Forbidden'),
'404': _('Not found'),
'405': _('Not allowed'),
'406': _('Not acceptable'),
'407': _('Registration required'),
'408': _('Request timeout'),
'409': _('Conflict'),
'500': _('Internal server error'),
'501': _('Feature not implemented'),
'502': _('Remote server error'),
'503': _('Service unavailable'),
'504': _('Remote server timeout'),
'510': _('Disconnected'),
'302': 'Redirect',
'400': 'Bad request',
'401': 'Not authorized',
'402': 'Payment required',
'403': 'Forbidden',
'404': 'Not found',
'405': 'Not allowed',
'406': 'Not acceptable',
'407': 'Registration required',
'408': 'Request timeout',
'409': 'Conflict',
'500': 'Internal server error',
'501': 'Feature not implemented',
'502': 'Remote server error',
'503': 'Service unavailable',
'504': 'Remote server timeout',
'510': 'Disconnected',
}
possible_show = {'available':None,
......
......@@ -11,7 +11,6 @@ Add some facilities that are not available on the XEP_0045
slix plugin
"""
from gettext import gettext as _
from xml.etree import cElementTree as ET
from common import safeJID
......@@ -43,10 +42,10 @@ def destroy_room(xmpp, room, reason='', altroom=''):
iq.append(query)
def callback(iq):
if not iq or iq['type'] == 'error':
xmpp.core.information(_('Unable to destroy room %s') % room,
_('Info'))
xmpp.core.information('Unable to destroy room %s' % room,
'Info')
else:
xmpp.core.information(_('Room %s destroyed') % room, _('Info'))
xmpp.core.information('Room %s destroyed' % room, 'Info')
iq.send(callback=callback)
return True
......
......@@ -3,89 +3,87 @@ Collection of mappings for PEP moods/activities
extracted directly from the XEP
"""
from gettext import gettext as _
MOODS = {
'afraid': _('Afraid'),
'amazed': _('Amazed'),
'angry': _('Angry'),
'amorous': _('Amorous'),
'annoyed': _('Annoyed'),
'anxious': _('Anxious'),
'aroused': _('Aroused'),
'ashamed': _('Ashamed'),
'bored': _('Bored'),
'brave': _('Brave'),
'calm': _('Calm'),
'cautious': _('Cautious'),
'cold': _('Cold'),
'confident': _('Confident'),
'confused': _('Confused'),
'contemplative': _('Contemplative'),
'contented': _('Contented'),
'cranky': _('Cranky'),
'crazy': _('Crazy'),
'creative': _('Creative'),
'curious': _('Curious'),
'dejected': _('Dejected'),
'depressed': _('Depressed'),
'disappointed': _('Disappointed'),
'disgusted': _('Disgusted'),
'dismayed': _('Dismayed'),
'distracted': _('Distracted'),
'embarrassed': _('Embarrassed'),
'envious': _('Envious'),
'excited': _('Excited'),
'flirtatious': _('Flirtatious'),
'frustrated': _('Frustrated'),
'grumpy': _('Grumpy'),
'guilty': _('Guilty'),
'happy': _('Happy'),
'hopeful': _('Hopeful'),
'hot': _('Hot'),
'humbled': _('Humbled'),
'humiliated': _('Humiliated'),
'hungry': _('Hungry'),
'hurt': _('Hurt'),
'impressed': _('Impressed'),
'in_awe': _('In awe'),
'in_love': _('In love'),
'indignant': _('Indignant'),
'interested': _('Interested'),
'intoxicated': _('Intoxicated'),
'invincible': _('Invincible'),
'jealous': _('Jealous'),
'lonely': _('Lonely'),
'lucky': _('Lucky'),
'mean': _('Mean'),
'moody': _('Moody'),
'nervous': _('Nervous'),