From c31dbfd76b520e9442080ebb87ccd1dbd91e0876 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 6 Dec 2024 11:34:38 +0100 Subject: [PATCH] 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. --- src/i18n.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/i18n.py b/src/i18n.py index 4557fb758..d428e8e2d 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -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,15 +263,14 @@ class _PluginInternationalization: """Main function. This is the function which is called when a plugin runs _()""" + if untranslated.__class__ is InternationalizedString: + untranslated = untranslated._origin + normalizedUntranslated = normalize(untranslated, 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 def _translate(self, string):