Skip to content

Commit

Permalink
i18n: Remove hacks for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Dec 19, 2024
1 parent 467fd54 commit 56e06a9
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def getLocalePath(name, localeName, extension):
return '%s/%s.%s' % (directory, localeName, extension)

i18nClasses = weakref.WeakValueDictionary()
internationalizedCommands = weakref.WeakValueDictionary()
internationalizedCommands = weakref.WeakSet()

def reloadLocalesIfRequired():
global currentLocale
Expand All @@ -132,7 +132,7 @@ def reloadLocales():

for pluginClass in i18nClasses.values():
pluginClass.loadLocale()
for command in list(internationalizedCommands.values()):
for command in list(internationalizedCommands):
internationalizeDocstring(command)
utils.str._relocalizeFunctions(PluginInternationalization())

Expand Down Expand Up @@ -331,19 +331,10 @@ def localizeFunction(self, name):
return self._l10nFunctions[name]


try:
class InternationalizedString(str):
"""Simple subclass to str, that allow to add attributes. Also used to
know if a string is already localized"""
__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
class InternationalizedString(str):
"""Simple subclass to str, that allow to add attributes. Also used to
know if a string is already localized"""
__slots__ = ('_original', '_internationalizer')


def internationalizeDocstring(obj):
Expand All @@ -354,7 +345,7 @@ def internationalizeDocstring(obj):
return obj
plugin_module = sys.modules[obj.__module__]
if '_' in plugin_module.__dict__:
internationalizedCommands.update({hash(obj): obj})
internationalizedCommands.add(obj)
try:
obj.__doc__ = plugin_module._.__call__(obj.__doc__)
# We use _.__call__() instead of _() because of a pygettext warning.
Expand Down

0 comments on commit 56e06a9

Please sign in to comment.