Skip to content

Commit

Permalink
[processing] i18n support in grass, R, OTB and example providers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 17, 2015
1 parent ad758aa commit 321ff1b
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 175 deletions.
Expand Up @@ -69,12 +69,12 @@ def defineCharacteristics(self):

# We add the input vector layer. It can have any kind of geometry
# It is a mandatory (not optional) one, hence the False argument
self.addParameter(ParameterVector(self.INPUT_LAYER, 'Input layer',
[ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY], False))

# We add a vector layer as output
self.addOutput(OutputVector(self.OUTPUT_LAYER,
'Output layer with selected features'))
self.tr('Output layer with selected features')))

def processAlgorithm(self, progress):
"""Here is where the processing itself takes place."""
Expand Down
Expand Up @@ -55,8 +55,8 @@ def initializeSettings(self):
"""
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting('Example algorithms',
ExampleAlgorithmProvider.MY_DUMMY_SETTING,
'Example setting', 'Default value'))
ExampleAlgorithmProvider.MY_DUMMY_SETTING,
'Example setting', 'Default value'))

def unload(self):
"""Setting should be removed here, so they do not appear anymore
Expand Down
42 changes: 22 additions & 20 deletions python/plugins/processing/algs/grass/GrassAlgorithm.py
Expand Up @@ -137,17 +137,16 @@ def defineCharacteristicsFromFile(self):
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS algorithm: '
+ self.descriptionFile + '\n' + line)
self.tr('Could not open GRASS algorithm: %s.\n%s' % (self.descriptionFile, line))
raise e
lines.close()

self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER,
'GRASS region extent'))
self.tr('GRASS region extent')))
if hasRasterOutput:
self.addParameter(ParameterNumber(
self.GRASS_REGION_CELLSIZE_PARAMETER,
'GRASS region cellsize (leave 0 for default)',
self.tr('GRASS region cellsize (leave 0 for default)'),
0, None, 0.0))
if hasVectorInput:
param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER,
Expand Down Expand Up @@ -197,9 +196,9 @@ def processAlgorithm(self, progress):
if system.isWindows():
path = GrassUtils.grassPath()
if path == '':
raise GeoAlgorithmExecutionException('GRASS folder is not \
configured.\nPlease configure it before running GRASS \
algorithms.')
raise GeoAlgorithmExecutionException(
self.tr('GRASS folder is not configured.\nPlease '
'configure it before running GRASS algorithms.'))

commands = []
self.exportedLayers = {}
Expand Down Expand Up @@ -390,7 +389,7 @@ def processAlgorithm(self, progress):
# 4: Run GRASS

loglines = []
loglines.append('GRASS execution commands')
loglines.append(self.tr('GRASS execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
Expand Down Expand Up @@ -491,11 +490,12 @@ def commandLineName(self):
def checkBeforeOpeningParametersDialog(self):
msg = GrassUtils.checkGrassIsInstalled()
if msg is not None:
html = '<p>This algorithm requires GRASS to be run. \
Unfortunately, it seems that GRASS is not installed in \
your system, or it is not correctly configured to be used \
from QGIS</p>'
html += '<p><a href="http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS to be used with QGIS</p>'
html = self.tr(
'<p>This algorithm requires GRASS to be run. Unfortunately, '
'it seems that GRASS is not installed in your system, or it '
'is not correctly configured to be used from QGIS</p>'
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
'to know more about how to install and configure GRASS to be used with QGIS</p>')
return html

def checkParameterValuesBeforeExecuting(self):
Expand All @@ -511,15 +511,17 @@ def checkParameterValuesBeforeExecuting(self):
def getPostProcessingErrorMessage(self, wrongLayers):
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
msg = GrassUtils.checkGrassIsInstalled(True)
html += '<p>This algorithm requires GRASS to be run. A test \
to check if GRASS is correctly installed and configured in \
your system has been performed, with the following \
result:</p><ul><i>'
html += self.tr(
'<p>This algorithm requires GRASS to be run. A test to check '
'if GRASS is correctly installed and configured in your system '
'has been performed, with the following result:</p><ul><i>')
if msg is None:
html += 'GRASS seems to be correctly installed and \
configured</i></li></ul>'
html += self.tr('GRASS seems to be correctly installed and '
'configured</i></li></ul>')
else:
html += msg + '</i></li></ul>'
html += '<p><a href= "http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS to be used with QGIS</p>'
html += self.tr(
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
'to know more about how to install and configure GRASS to be used with QGIS</p>')

return html
22 changes: 10 additions & 12 deletions python/plugins/processing/algs/grass/GrassAlgorithmProvider.py
Expand Up @@ -47,17 +47,17 @@ def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_FOLDER, 'GRASS folder',
GrassUtils.grassPath()))
GrassUtils.GRASS_FOLDER, self.tr('GRASS folder'),
GrassUtils.grassPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_WIN_SHELL, 'Msys folder',
GrassUtils.grassWinShell()))
GrassUtils.GRASS_WIN_SHELL, self.tr('Msys folder'),
GrassUtils.grassWinShell()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_LOG_COMMANDS,
'Log execution commands', False))
GrassUtils.GRASS_LOG_COMMANDS,
self.tr('Log execution commands'), False))
ProcessingConfig.addSetting(Setting(self.getDescription(),
GrassUtils.GRASS_LOG_CONSOLE,
'Log console output', False))
GrassUtils.GRASS_LOG_CONSOLE,
self.tr('Log console output'), False))

def unload(self):
AlgorithmProvider.unload(self)
Expand All @@ -78,12 +78,10 @@ def createAlgsList(self):
self.preloadedAlgs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS algorithm: '
+ descriptionFile)
self.tr('Could not open GRASS algorithm: %s' % descriptionFile))
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS algorithm: '
+ descriptionFile)
self.tr('Could not open GRASS algorithm: %s' % descriptionFile))
self.preloadedAlgs.append(nviz())

def _loadAlgorithms(self):
Expand Down
33 changes: 21 additions & 12 deletions python/plugins/processing/algs/grass/GrassUtils.py
Expand Up @@ -354,15 +354,16 @@ def checkGrassIsInstalled(ignorePreviousState=False):
if isWindows():
path = GrassUtils.grassPath()
if path == '':
return 'GRASS folder is not configured.\nPlease configure \
it before running GRASS algorithms.'
return GrassUtils.tr(
'GRASS folder is not configured.\nPlease configure '
'it before running GRASS algorithms.')
cmdpath = os.path.join(path, 'bin', 'r.out.gdal.exe')
if not os.path.exists(cmdpath):
return 'The specified GRASS folder does not contain a valid \
set of GRASS modules.\n' \
+ 'Please, go to the Processing settings dialog, and \
check that the GRASS\n' \
+ 'folder is correctly configured'
return GrassUtils.tr(
'The specified GRASS folder does not contain a valid '
'set of GRASS modules. Please, go to the Processing '
'settings dialog, and check that the GRASS folder is '
'correctly configured')

if not ignorePreviousState:
if GrassUtils.isGrassInstalled:
Expand All @@ -381,11 +382,19 @@ def checkGrassIsInstalled(ignorePreviousState=False):
None,
)
if not os.path.exists(result['output']):
return 'It seems that GRASS is not correctly installed and \
configured in your system.\nPlease install it before \
running GRASS algorithms.'
return GrassUtils.tr(
'It seems that GRASS is not correctly installed and '
'configured in your system.\nPlease install it before '
'running GRASS algorithms.')
except:
return 'Error while checking GRASS installation. GRASS might not \
be correctly configured.\n'
return GrassUtils.tr(
'Error while checking GRASS installation. GRASS might not '
'be correctly configured.\n')

GrassUtils.isGrassInstalled = True

@staticmethod
def tr(string, context=''):
if context == '':
context = 'GrassUtils'
return QCoreApplication.translate(context, string)
20 changes: 11 additions & 9 deletions python/plugins/processing/algs/grass/nviz.py
Expand Up @@ -53,17 +53,19 @@ def defineCharacteristics(self):
self.name = 'nviz'
self.group = 'Visualization(NVIZ)'
self.addParameter(ParameterMultipleInput(nviz.ELEVATION,
'Raster file(s) for elevation',
ParameterMultipleInput.TYPE_RASTER, True))
self.addParameter(ParameterMultipleInput(nviz.VECTOR, 'Vector lines/areas overlay file(s)',
ParameterMultipleInput.TYPE_VECTOR_ANY, True))
self.addParameter(ParameterMultipleInput(nviz.COLOR, 'Raster file(s) for color',
ParameterMultipleInput.TYPE_RASTER, True))
self.tr('Raster file(s) for elevation'),
ParameterMultipleInput.TYPE_RASTER, True))
self.addParameter(ParameterMultipleInput(nviz.VECTOR,
self.tr('Vector lines/areas overlay file(s)'),
ParameterMultipleInput.TYPE_VECTOR_ANY, True))
self.addParameter(ParameterMultipleInput(nviz.COLOR,
self.tr('Raster file(s) for color'),
ParameterMultipleInput.TYPE_RASTER, True))
self.addParameter(ParameterExtent(nviz.GRASS_REGION_EXTENT_PARAMETER,
'GRASS region extent'))
self.tr('GRASS region extent')))
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER,
'GRASS region cellsize (leave 0 for default)', 0,
None, 0.0))
self.tr('GRASS region cellsize (leave 0 for default)'),
0, None, 0.0))

def processAlgorithm(self, progress):
commands = []
Expand Down
43 changes: 23 additions & 20 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -138,17 +138,16 @@ def defineCharacteristicsFromFile(self):
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS GIS 7 algorithm: '
+ self.descriptionFile + '\n' + line)
self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line)))
raise e
lines.close()

self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER,
'GRASS GIS 7 region extent'))
self.tr('GRASS GIS 7 region extent')))
if hasRasterOutput:
self.addParameter(ParameterNumber(
self.GRASS_REGION_CELLSIZE_PARAMETER,
'GRASS GIS 7 region cellsize (leave 0 for default)',
self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'),
0, None, 0.0))
if hasVectorInput:
param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER,
Expand Down Expand Up @@ -198,9 +197,9 @@ def processAlgorithm(self, progress):
if system.isWindows():
path = Grass7Utils.grassPath()
if path == '':
raise GeoAlgorithmExecutionException('GRASS GIS 7 folder is not \
configured.\nPlease configure it before running GRASS GIS 7\
algorithms.')
raise GeoAlgorithmExecutionException(
self.tr('GRASS GIS 7 folder is not configured. Please '
'configure it before running GRASS GIS 7 algorithms.'))

commands = []
self.exportedLayers = {}
Expand Down Expand Up @@ -392,7 +391,7 @@ def processAlgorithm(self, progress):
# 4: Run GRASS

loglines = []
loglines.append('GRASS GIS 7 execution commands')
loglines.append(self.tr('GRASS GIS 7 execution commands'))
for line in commands:
progress.setCommand(line)
loglines.append(line)
Expand Down Expand Up @@ -493,11 +492,13 @@ def commandLineName(self):
def checkBeforeOpeningParametersDialog(self):
msg = Grass7Utils.checkGrass7IsInstalled()
if msg is not None:
html = '<p>This algorithm requires GRASS GIS 7 to be run. \
Unfortunately, it seems that GRASS GIS 7 is not installed in \
your system, or it is not correctly configured to be used \
from QGIS</p>'
html += '<p><a href="http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>' # FIXME update URL or page
html = self.tr(
'<p>This algorithm requires GRASS GIS 7 to be run. '
'Unfortunately, it seems that GRASS GIS 7 is not installed in '
'your system, or it is not correctly configured to be used '
'from QGIS</p>'
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual/processing/3rdParty.html">Click here</a> '
'to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>') # FIXME update URL or page
return html

def checkParameterValuesBeforeExecuting(self):
Expand All @@ -513,15 +514,17 @@ def checkParameterValuesBeforeExecuting(self):
def getPostProcessingErrorMessage(self, wrongLayers):
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
msg = Grass7Utils.checkGrass7IsInstalled(True)
html += '<p>This algorithm requires GRASS GIS 7 to be run. A test \
to check if GRASS GIS 7 is correctly installed and configured in \
your system has been performed, with the following \
result:</p><ul><i>'
html += self.tr(
'<p>This algorithm requires GRASS GIS 7 to be run. A test '
'to check if GRASS GIS 7 is correctly installed and configured in '
'your system has been performed, with the following result:</p><ul><i>')
if msg is None:
html += 'GRASS GIS 7 seems to be correctly installed and \
configured</i></li></ul>'
html += self.tr(
'GRASS GIS 7 seems to be correctly installed and configured</i></li></ul>')
else:
html += msg + '</i></li></ul>'
html += '<p><a href= "http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>'
html += self.tr(
'<p><a href="http://docs.qgis.org/testing/en/docs/user_manual//3rdParty.html">Click here</a> '
'to know more about how to install and configure GRASS GIS 7 to be used with QGIS</p>')

return html
22 changes: 10 additions & 12 deletions python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
Expand Up @@ -49,17 +49,17 @@ def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_FOLDER, 'GRASS7 folder',
Grass7Utils.grassPath()))
Grass7Utils.GRASS_FOLDER, self.tr('GRASS7 folder'),
Grass7Utils.grassPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_WIN_SHELL, 'Msys folder',
Grass7Utils.grassWinShell()))
Grass7Utils.GRASS_WIN_SHELL, self.tr('Msys folder'),
Grass7Utils.grassWinShell()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_LOG_COMMANDS,
'Log execution commands', False))
Grass7Utils.GRASS_LOG_COMMANDS,
self.tr('Log execution commands'), False))
ProcessingConfig.addSetting(Setting(self.getDescription(),
Grass7Utils.GRASS_LOG_CONSOLE,
'Log console output', False))
Grass7Utils.GRASS_LOG_CONSOLE,
self.tr('Log console output'), False))

def unload(self):
AlgorithmProvider.unload(self)
Expand All @@ -80,12 +80,10 @@ def createAlgsList(self):
self.preloadedAlgs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS GIS 7 algorithm: '
+ descriptionFile)
self.tr('Could not open GRASS GIS 7 algorithm: %s' % descriptionFile))
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS GIS 7 algorithm: '
+ descriptionFile)
self.tr('Could not open GRASS GIS 7 algorithm: %s' % descriptionFile))
self.preloadedAlgs.append(nviz7())

def _loadAlgorithms(self):
Expand Down

0 comments on commit 321ff1b

Please sign in to comment.