Skip to content

Commit c31dbfd

Browse files
committed
Fix interference of wrap() and internationalizeDocstring()
Most commands are decorated with @internationalizeDocstring then with wrap(). wrap() itself calls internationalizeDocstring(), so that plugins wrapping with @internationalizeDocstring() is now optional; but many still do it. This means that docstrings went twice through the _PluginInternationalization. This fixes the bug that on the second run, it would try to translate again the translated message, which fails (because the translated message is not in English); and then fell back to the original string (which is in English). This commit changes the behavior to return the already-translated string directly instead.
1 parent b76a6db commit c31dbfd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/i18n.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###
2-
# Copyright (c) 2010-2021, Valentin Lorentz
2+
# Copyright (c) 2010-2024, Valentin Lorentz
33
# All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
@@ -263,15 +263,14 @@ def __call__(self, untranslated):
263263
"""Main function.
264264
265265
This is the function which is called when a plugin runs _()"""
266+
if untranslated.__class__ is InternationalizedString:
267+
untranslated = untranslated._origin
268+
266269
normalizedUntranslated = normalize(untranslated, True)
267270
try:
268271
string = self._translate(normalizedUntranslated)
269272
return self._addTracker(string, untranslated)
270273
except KeyError:
271-
pass
272-
if untranslated.__class__ is InternationalizedString:
273-
return untranslated._original
274-
else:
275274
return untranslated
276275

277276
def _translate(self, string):

0 commit comments

Comments
 (0)