mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-05-07 23:27:26 +02:00
Bug fixes
This commit is contained in:
parent
fd590dfdf7
commit
198f8267eb
31
src/i18n.py
31
src/i18n.py
@ -57,7 +57,16 @@ def import_conf():
|
|||||||
i18nClasses[key].loadLocale()
|
i18nClasses[key].loadLocale()
|
||||||
|
|
||||||
def get_plugin_dir(plugin_name):
|
def get_plugin_dir(plugin_name):
|
||||||
filename = sys.modules[plugin_name].__file__
|
filename = None
|
||||||
|
try:
|
||||||
|
filename = sys.modules[plugin_name].__file__
|
||||||
|
except KeyError: # This is odd
|
||||||
|
pass
|
||||||
|
if filename == None:
|
||||||
|
try:
|
||||||
|
filename = sys.modules['supybot.plugins.' + plugin_name].__file__
|
||||||
|
except KeyError: # This is odder
|
||||||
|
return
|
||||||
if filename.endswith(".pyc"):
|
if filename.endswith(".pyc"):
|
||||||
filename = filename[0:-1]
|
filename = filename[0:-1]
|
||||||
|
|
||||||
@ -69,7 +78,10 @@ def get_plugin_dir(plugin_name):
|
|||||||
|
|
||||||
def getLocalePath(name, localeName, extension):
|
def getLocalePath(name, localeName, extension):
|
||||||
if name != 'supybot':
|
if name != 'supybot':
|
||||||
directory = get_plugin_dir(name) + 'locale'
|
try:
|
||||||
|
directory = get_plugin_dir(name) + 'locale'
|
||||||
|
except TypeError: # get_plugin_dir returned None
|
||||||
|
return ''
|
||||||
else:
|
else:
|
||||||
import ansi # Any Supybot plugin could fit
|
import ansi # Any Supybot plugin could fit
|
||||||
directory = ansi.__file__[0:-len('ansi.pyc')] + 'locale'
|
directory = ansi.__file__[0:-len('ansi.pyc')] + 'locale'
|
||||||
@ -90,14 +102,11 @@ def reloadLocals():
|
|||||||
|
|
||||||
i18nSupybot = None
|
i18nSupybot = None
|
||||||
def PluginInternationalization(name='supybot'):
|
def PluginInternationalization(name='supybot'):
|
||||||
# This is a proxy, that prevent Supybot against having more than one
|
# This is a proxy that prevents having several objects for the same plugin
|
||||||
# internationalizer
|
if i18nClasses.has_key(name):
|
||||||
global i18nSupybot
|
return i18nClasses[name]
|
||||||
if name != 'supybot':
|
else:
|
||||||
return _PluginInternationalization(name)
|
return _PluginInternationalization(name)
|
||||||
elif i18nSupybot == None:
|
|
||||||
i18nSupybot = _PluginInternationalization('supybot')
|
|
||||||
return i18nSupybot
|
|
||||||
|
|
||||||
class _PluginInternationalization:
|
class _PluginInternationalization:
|
||||||
"""Internationalization managment for a plugin."""
|
"""Internationalization managment for a plugin."""
|
||||||
@ -127,8 +136,6 @@ class _PluginInternationalization:
|
|||||||
self._parse(translationFile)
|
self._parse(translationFile)
|
||||||
except IOError: # The translation is unavailable
|
except IOError: # The translation is unavailable
|
||||||
self.translations = {}
|
self.translations = {}
|
||||||
return
|
|
||||||
|
|
||||||
def _parse(self, translationFile):
|
def _parse(self, translationFile):
|
||||||
"""A .po files parser.
|
"""A .po files parser.
|
||||||
|
|
||||||
@ -268,4 +275,4 @@ def internationalizeDocstring(obj):
|
|||||||
internationalizedCommands.update({hash(obj): obj})
|
internationalizedCommands.update({hash(obj): obj})
|
||||||
obj.__doc__=sys.modules[obj.__module__]._.__call__(obj.__doc__)
|
obj.__doc__=sys.modules[obj.__module__]._.__call__(obj.__doc__)
|
||||||
# We use _.__call__() instead of _() because of a pygettext warning.
|
# We use _.__call__() instead of _() because of a pygettext warning.
|
||||||
return obj
|
return obj
|
||||||
|
Loading…
x
Reference in New Issue
Block a user