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.
This commit is contained in:
Val Lorentz 2024-12-20 07:57:23 +01:00 committed by GitHub
parent 912e334f6b
commit aaeab253a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 @@ class _PluginInternationalization:
"""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.