Skip to content

Commit

Permalink
processing: enable translation for parameter descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 5, 2019
1 parent 6564da0 commit 9f1fcb7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -68,7 +68,7 @@

from processing.core.ProcessingConfig import ProcessingConfig

from processing.core.parameters import (getParameterFromString)
from processing.core.parameters import getParameterFromString

from .Grass7Utils import Grass7Utils

Expand Down Expand Up @@ -203,6 +203,7 @@ def defineCharacteristicsFromFile(self):
self._name = self.grass7Name
else:
self._name = line[:line.find(' ')].lower()
self._short_description = QCoreApplication.translate("GrassAlgorithm", line)
self._display_name = self._name
# Read the grass group
line = lines.readline().strip('\n').strip()
Expand All @@ -219,7 +220,7 @@ def defineCharacteristicsFromFile(self):
line = line.strip('\n').strip()
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Hardcoded|'):])
parameter = getParameterFromString(line)
parameter = getParameterFromString(line, "GrassAlgorithm")
if parameter is not None:
self.params.append(parameter)
if isinstance(parameter, (QgsProcessingParameterVectorLayer, QgsProcessingParameterFeatureSource)):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/i.py
Expand Up @@ -182,7 +182,7 @@ def verifyRasterNum(alg, parameters, context, rasters, mini, maxi=None):
# alg.removeOutputFromName(output)

# # Create output parameter
# param = getParameterFromString("ParameterString|{}|output file|None|False|False".format(output))
# param = getParameterFromString("ParameterString|{}|output file|None|False|False".format(output), 'GrassAlgorithm')
# param.value = outputFile.value
# alg.addParameter(param)

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OtbAlgorithm.py
Expand Up @@ -135,7 +135,7 @@ def defineCharacteristicsFromFile(self):
options = params[2].split(';')
param = OtbParameterChoice(params[0], params[1], options, params[3], params[4])
else:
param = getParameterFromString(line)
param = getParameterFromString(line, 'OtbAlgorithm')

#if parameter is None, then move to next line and continue
if param is None:
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/saga/SagaParameters.py
Expand Up @@ -26,8 +26,7 @@

__revision__ = '$Format:%H$'

import os
import importlib
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import QgsProcessingParameterRasterDestination
from processing.core.parameters import getParameterFromString

Expand Down Expand Up @@ -70,6 +69,7 @@ def create_parameter_from_line(line):
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
params[4] = True if params[4].lower() == 'true' else False
return SagaImageOutputParam(*params)
param = SagaImageOutputParam(*params)
param.setDescription(QCoreApplication.translate("SAGAAlgorithm", param.description()))
else:
return getParameterFromString(line)
return getParameterFromString(line, "SAGAAlgorithm")
4 changes: 3 additions & 1 deletion python/plugins/processing/core/parameters.py
Expand Up @@ -89,7 +89,7 @@
PARAMETER_RASTER_DESTINATION = 'rasterDestination'


def getParameterFromString(s):
def getParameterFromString(s, context):
# Try the parameter definitions used in description files
if '|' in s and (s.startswith("QgsProcessingParameter") or s.startswith("*QgsProcessingParameter") or s.startswith('Parameter') or s.startswith('*Parameter')):
isAdvanced = False
Expand Down Expand Up @@ -244,6 +244,8 @@ def getParameterFromString(s):
if isAdvanced:
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)

param.setDescription(QCoreApplication.translate(context, param.description()))

return param
else:
return None
Expand Down
26 changes: 13 additions & 13 deletions scripts/processing2ui.pl
Expand Up @@ -48,6 +48,13 @@ sub xmlescape {
my $name = scalar(<I>);
my $desc = scalar(<I>);
my $group = scalar(<I>);

while( my($class, $name, $description, $rest) = split /\|/, scalar(<I>) ) {
next unless defined $description;
$description =~ s/\s+$//;
$strings{"GrassAlgorithm"}{$description} = 1
}

close I;

chop $desc;
Expand All @@ -57,23 +64,16 @@ sub xmlescape {
$strings{"GrassAlgorithm"}{$group} = 1;
}

for my $f (<python/plugins/processing/algs/taudem/description/*/*.txt>) {
for my $f (<python/plugins/processing/algs/saga/description/*/*.txt>) {
open I, $f;
my $desc = scalar(<I>);
my $name = scalar(<I>);
my $group = scalar(<I>);
close I;

chop $desc;
chop $group;

$strings{"TAUDEMAlgorithm"}{$desc} = 1;
$strings{"TAUDEMAlgorithm"}{$group} = 1;
}
while( my($class, $name, $description, $rest) = split /\|/, scalar(<I>) ) {
next unless defined $description;
$description =~ s/\s+$//;
$strings{"SAGAAlgorithm"}{$description} = 1
}

for my $f (<python/plugins/processing/algs/saga/description/*/*.txt>) {
open I, $f;
my $desc = scalar(<I>);
close I;

chop $desc;
Expand Down

0 comments on commit 9f1fcb7

Please sign in to comment.