mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Bug fixes (mainly the &config help internationalization)
This commit is contained in:
parent
bec550fb5f
commit
4dcd7f7fb4
@ -199,7 +199,7 @@ class Misc(callbacks.Plugin):
|
||||
'you want help with.'), names))
|
||||
else:
|
||||
assert cbs, 'Odd, maxL == command, but no cbs.'
|
||||
irc.reply(cbs[0].getCommandHelp(command, False))
|
||||
irc.reply(_.__call__(cbs[0].getCommandHelp(command, False)))
|
||||
else:
|
||||
irc.error(format(_('There is no command %q.'),
|
||||
callbacks.formatCommand(command)))
|
||||
|
53
src/i18n.py
53
src/i18n.py
@ -57,7 +57,13 @@ def import_conf():
|
||||
i18nClasses[key].loadLocale()
|
||||
|
||||
def get_plugin_dir(plugin_name):
|
||||
filename = sys.modules[plugin_name].__file__
|
||||
filename = None
|
||||
try:
|
||||
filename = sys.modules[plugin_name].__file__
|
||||
except KeyError: # It sometimes happens with Owner
|
||||
pass
|
||||
if filename == None:
|
||||
filename = sys.modules['supybot.plugins.' + plugin_name].__file__
|
||||
if filename.endswith(".pyc"):
|
||||
filename = filename[0:-1]
|
||||
|
||||
@ -164,7 +170,7 @@ class _PluginInternationalization:
|
||||
if len(data) == 0: # Multiline mode
|
||||
step = IN_MSGSTR
|
||||
else:
|
||||
self._translate(untranslated, data)
|
||||
self._addToDatabase(untranslated, data)
|
||||
step = WAITING_FOR_MSGID
|
||||
|
||||
|
||||
@ -175,25 +181,47 @@ class _PluginInternationalization:
|
||||
step = WAITING_FOR_MSGID
|
||||
if translated == '':
|
||||
translated = untranslated
|
||||
self._translate(untranslated, translated)
|
||||
self._addToDatabase(untranslated, translated)
|
||||
|
||||
def _translate(self, untranslated, translated):
|
||||
self.translations.update({self._unescape(untranslated):
|
||||
self._unescape(translated)})
|
||||
def _addToDatabase(self, untranslated, translated):
|
||||
untranslated = self._unescape(untranslated)
|
||||
translated = self._unescape(translated)
|
||||
self.translations.update({untranslated: translated})
|
||||
|
||||
def _unescape(self, string):
|
||||
return str.replace(string, '\\n', '\n')
|
||||
import supybot.utils as utils
|
||||
return utils.str.normalizeWhitespace(str.replace(string, '\\n', '\n'))
|
||||
|
||||
def __call__(self, untranslated):
|
||||
if untranslated.__class__ == internationalizedString:
|
||||
return untranslated._original
|
||||
untranslated = __import__('supybot').utils.str.normalizeWhitespace(untranslated)
|
||||
if not 'conf' in globals():
|
||||
return untranslated
|
||||
if self.currentLocaleName != conf.supybot.language():
|
||||
# If the locale has been changed
|
||||
reloadLocals()
|
||||
try:
|
||||
return self.translations[untranslated]
|
||||
string = self._translate(untranslated)
|
||||
return self._addTracker(string, untranslated)
|
||||
except KeyError:
|
||||
return untranslated
|
||||
pass
|
||||
return untranslated
|
||||
|
||||
def _translate(self, string):
|
||||
if string.__class__ == internationalizedString:
|
||||
return string._internationalizer(string.untranslated)
|
||||
else:
|
||||
return self.translations[string]
|
||||
|
||||
def _addTracker(self, string, untranslated):
|
||||
if string.__class__ == internationalizedString:
|
||||
return string
|
||||
else:
|
||||
string = internationalizedString(string)
|
||||
string._original = untranslated
|
||||
string._internationalizer = self
|
||||
return string
|
||||
|
||||
def _loadL10nCode(self):
|
||||
if self.name != 'supybot':
|
||||
@ -260,6 +288,13 @@ class internationalizedFunction:
|
||||
def restore(self):
|
||||
self.__call__ = self._origin
|
||||
|
||||
class internationalizedString(str):
|
||||
pass
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# self.__parent.__init__(*args, **kwargs)
|
||||
# self._original = str(self)
|
||||
# self._internationalizer = None
|
||||
|
||||
def internationalizeDocstring(obj):
|
||||
"""Decorates functions and internationalize their docstring.
|
||||
|
||||
|
@ -35,6 +35,7 @@ import string
|
||||
import textwrap
|
||||
|
||||
import supybot.utils as utils
|
||||
import supybot.i18n as i18n
|
||||
|
||||
def error(s):
|
||||
"""Replace me with something better from another module!"""
|
||||
@ -211,7 +212,7 @@ class Group(object):
|
||||
self.__nonExistentEntry(attr)
|
||||
|
||||
def help(self):
|
||||
return self._help
|
||||
return i18n.PluginInternationalization().__call__(self._help)
|
||||
|
||||
def get(self, attr):
|
||||
# Not getattr(self, attr) because some nodes might have groups that
|
||||
|
Loading…
Reference in New Issue
Block a user