From 94fd78ca51e6d3aa7d6a1ac190df76832365e959 Mon Sep 17 00:00:00 2001 From: Nicolas Godet <39594821+nicogodet@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:13:06 +0200 Subject: [PATCH] Provide __class__.__name__ as translation context instead of hardcoded class name --- python/plugins/grassprovider/grass_algorithm.py | 12 ++++-------- python/plugins/grassprovider/grass_provider.py | 6 ++---- python/plugins/grassprovider/grass_utils.py | 8 +++----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/python/plugins/grassprovider/grass_algorithm.py b/python/plugins/grassprovider/grass_algorithm.py index d0743b51ebf..749531f03f8 100644 --- a/python/plugins/grassprovider/grass_algorithm.py +++ b/python/plugins/grassprovider/grass_algorithm.py @@ -221,10 +221,8 @@ class GrassAlgorithm(QgsProcessingAlgorithm): | QgsProcessingAlgorithm.Flag.FlagDisplayNameIsLiteral ) - def tr(self, string, context=""): - if context == "": - context = self.__class__.__name__ - return QCoreApplication.translate(context, string) + def tr(self, string: str): + return QCoreApplication.translate(self.__class__.__name__, string) def helpUrl(self): helpPath = GrassUtils.grassHelpPath() @@ -287,10 +285,8 @@ class GrassAlgorithm(QgsProcessingAlgorithm): parameter = getParameterFromString(param_string, "GrassAlgorithm") except Exception as e: QgsMessageLog.logMessage( - QCoreApplication.translate( - "GrassAlgorithm", "Could not open GRASS GIS algorithm: {0}" - ).format(self._name), - QCoreApplication.translate("GrassAlgorithm", "Processing"), + self.tr("Could not open GRASS GIS algorithm: {0}").format(self._name), + self.tr("Processing"), Qgis.MessageLevel.Critical, ) raise e diff --git a/python/plugins/grassprovider/grass_provider.py b/python/plugins/grassprovider/grass_provider.py index 19022c0d08c..58345e6a9b8 100644 --- a/python/plugins/grassprovider/grass_provider.py +++ b/python/plugins/grassprovider/grass_provider.py @@ -222,7 +222,5 @@ class GrassProvider(QgsProcessingProvider): def canBeActivated(self): return not bool(GrassUtils.checkGrassIsInstalled()) - def tr(self, string, context=""): - if context == "": - context = "Grass7AlgorithmProvider" - return QCoreApplication.translate(context, string) + def tr(self, string: str): + return QCoreApplication.translate(self.__class__.__name__, string) diff --git a/python/plugins/grassprovider/grass_utils.py b/python/plugins/grassprovider/grass_utils.py index 5e44af62c1b..13a256e36f8 100644 --- a/python/plugins/grassprovider/grass_utils.py +++ b/python/plugins/grassprovider/grass_utils.py @@ -628,11 +628,9 @@ class GrassUtils: "Please install it or configure your PATH environment variable." ) - @staticmethod - def tr(string, context=""): - if context == "": - context = "Grass7Utils" - return QCoreApplication.translate(context, string) + @classmethod + def tr(cls, string: str): + return QCoreApplication.translate(cls.__name__, string) @staticmethod def writeCommand(output, command):