Provide __class__.__name__ as translation context instead of hardcoded class name

This commit is contained in:
Nicolas Godet 2025-08-08 16:13:06 +02:00 committed by nicogodet
parent f0ae7ee526
commit 94fd78ca51
3 changed files with 9 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -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):