Merge pull request #62818 from nicogodet/fix-grassutils-tr

Provide `__class__.__name__` as translation context instead of hardcoded class name
This commit is contained in:
Alexander Bruy 2025-09-17 14:58:12 +01:00 committed by GitHub
commit 9a762e2ba8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 17 deletions

View File

@ -221,10 +221,8 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
| QgsProcessingAlgorithm.Flag.FlagDisplayNameIsLiteral | QgsProcessingAlgorithm.Flag.FlagDisplayNameIsLiteral
) )
def tr(self, string, context=""): def tr(self, string: str):
if context == "": return QCoreApplication.translate(self.__class__.__name__, string)
context = self.__class__.__name__
return QCoreApplication.translate(context, string)
def helpUrl(self): def helpUrl(self):
helpPath = GrassUtils.grassHelpPath() helpPath = GrassUtils.grassHelpPath()
@ -287,10 +285,8 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
parameter = getParameterFromString(param_string, "GrassAlgorithm") parameter = getParameterFromString(param_string, "GrassAlgorithm")
except Exception as e: except Exception as e:
QgsMessageLog.logMessage( QgsMessageLog.logMessage(
QCoreApplication.translate( self.tr("Could not open GRASS GIS algorithm: {0}").format(self._name),
"GrassAlgorithm", "Could not open GRASS GIS algorithm: {0}" self.tr("Processing"),
).format(self._name),
QCoreApplication.translate("GrassAlgorithm", "Processing"),
Qgis.MessageLevel.Critical, Qgis.MessageLevel.Critical,
) )
raise e raise e

View File

@ -222,7 +222,5 @@ class GrassProvider(QgsProcessingProvider):
def canBeActivated(self): def canBeActivated(self):
return not bool(GrassUtils.checkGrassIsInstalled()) return not bool(GrassUtils.checkGrassIsInstalled())
def tr(self, string, context=""): def tr(self, string: str):
if context == "": return QCoreApplication.translate(self.__class__.__name__, string)
context = "Grass7AlgorithmProvider"
return QCoreApplication.translate(context, string)

View File

@ -628,11 +628,9 @@ class GrassUtils:
"Please install it or configure your PATH environment variable." "Please install it or configure your PATH environment variable."
) )
@staticmethod @classmethod
def tr(string, context=""): def tr(cls, string: str):
if context == "": return QCoreApplication.translate(cls.__name__, string)
context = "Grass7Utils"
return QCoreApplication.translate(context, string)
@staticmethod @staticmethod
def writeCommand(output, command): def writeCommand(output, command):