mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-25 12:31:04 -05:00
i18n: Remove hacks for Python 2
This commit is contained in:
parent
467fd5472f
commit
56e06a9ce8
23
src/i18n.py
23
src/i18n.py
@ -117,7 +117,7 @@ def getLocalePath(name, localeName, extension):
|
|||||||
return '%s/%s.%s' % (directory, localeName, extension)
|
return '%s/%s.%s' % (directory, localeName, extension)
|
||||||
|
|
||||||
i18nClasses = weakref.WeakValueDictionary()
|
i18nClasses = weakref.WeakValueDictionary()
|
||||||
internationalizedCommands = weakref.WeakValueDictionary()
|
internationalizedCommands = weakref.WeakSet()
|
||||||
|
|
||||||
def reloadLocalesIfRequired():
|
def reloadLocalesIfRequired():
|
||||||
global currentLocale
|
global currentLocale
|
||||||
@ -132,7 +132,7 @@ def reloadLocales():
|
|||||||
|
|
||||||
for pluginClass in i18nClasses.values():
|
for pluginClass in i18nClasses.values():
|
||||||
pluginClass.loadLocale()
|
pluginClass.loadLocale()
|
||||||
for command in list(internationalizedCommands.values()):
|
for command in list(internationalizedCommands):
|
||||||
internationalizeDocstring(command)
|
internationalizeDocstring(command)
|
||||||
utils.str._relocalizeFunctions(PluginInternationalization())
|
utils.str._relocalizeFunctions(PluginInternationalization())
|
||||||
|
|
||||||
@ -331,19 +331,10 @@ class _PluginInternationalization:
|
|||||||
return self._l10nFunctions[name]
|
return self._l10nFunctions[name]
|
||||||
|
|
||||||
|
|
||||||
try:
|
class InternationalizedString(str):
|
||||||
class InternationalizedString(str):
|
"""Simple subclass to str, that allow to add attributes. Also used to
|
||||||
"""Simple subclass to str, that allow to add attributes. Also used to
|
know if a string is already localized"""
|
||||||
know if a string is already localized"""
|
__slots__ = ('_original', '_internationalizer')
|
||||||
__slots__ = ('_original', '_internationalizer')
|
|
||||||
except TypeError:
|
|
||||||
# Fallback for CPython 2.x:
|
|
||||||
# TypeError: Error when calling the metaclass bases
|
|
||||||
# nonempty __slots__ not supported for subtype of 'str'
|
|
||||||
class InternationalizedString(str):
|
|
||||||
"""Simple subclass to str, that allow to add attributes. Also used to
|
|
||||||
know if a string is already localized"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def internationalizeDocstring(obj):
|
def internationalizeDocstring(obj):
|
||||||
@ -354,7 +345,7 @@ def internationalizeDocstring(obj):
|
|||||||
return obj
|
return obj
|
||||||
plugin_module = sys.modules[obj.__module__]
|
plugin_module = sys.modules[obj.__module__]
|
||||||
if '_' in plugin_module.__dict__:
|
if '_' in plugin_module.__dict__:
|
||||||
internationalizedCommands.update({hash(obj): obj})
|
internationalizedCommands.add(obj)
|
||||||
try:
|
try:
|
||||||
obj.__doc__ = plugin_module._.__call__(obj.__doc__)
|
obj.__doc__ = plugin_module._.__call__(obj.__doc__)
|
||||||
# We use _.__call__() instead of _() because of a pygettext warning.
|
# We use _.__call__() instead of _() because of a pygettext warning.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user