Skip to content

Commit

Permalink
Fix interference of wrap() and internationalizeDocstring()
Browse files Browse the repository at this point in the history
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.
progval authored Dec 20, 2024
1 parent 912e334 commit aaeab25
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/i18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (c) 2010-2021, Valentin Lorentz
# Copyright (c) 2010-2024, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -263,16 +263,17 @@ def __call__(self, untranslated):
"""Main function.
This is the function which is called when a plugin runs _()"""
normalizedUntranslated = normalize(untranslated, True)
if untranslated.__class__ is InternationalizedString:
originalUntranslated = untranslated._original
else:
originalUntranslated = untranslated

normalizedUntranslated = normalize(originalUntranslated, True)
try:
string = self._translate(normalizedUntranslated)
return self._addTracker(string, untranslated)
except KeyError:
pass
if untranslated.__class__ is InternationalizedString:
return untranslated._original
else:
return untranslated
string = originalUntranslated
return self._addTracker(string, untranslated)

def _translate(self, string):
"""Translate the string.

0 comments on commit aaeab25

Please sign in to comment.