Skip to content

Commit f935316

Browse files
committed
[processing] add full i18n support (still needs some work to mark all
strings as translatable)
1 parent 46effa1 commit f935316

17 files changed

+135
-76
lines changed

python/plugins/processing/core/AlgorithmProvider.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828
import os
29-
from PyQt4 import QtGui
29+
from PyQt4 import QtGui, QtCore
3030
from qgis.core import *
3131
from processing.core.ProcessingConfig import Setting, ProcessingConfig
3232

@@ -77,7 +77,7 @@ def initializeSettings(self):
7777
ProcessingConfig.settingIcons[self.getDescription()] = self.getIcon()
7878
name = 'ACTIVATE_' + self.getName().upper().replace(' ', '_')
7979
ProcessingConfig.addSetting(Setting(self.getDescription(), name,
80-
'Activate', self.activate))
80+
self.tr('Activate'), self.activate))
8181

8282
def unload(self):
8383
"""Do here anything that you want to be done when the provider
@@ -98,7 +98,7 @@ def getName(self):
9898
def getDescription(self):
9999
"""Returns the full name of the provider.
100100
"""
101-
return 'Generic algorithm provider'
101+
return self.tr('Generic algorithm provider')
102102

103103
def getIcon(self):
104104
return QtGui.QIcon(os.path.dirname(__file__) + '/../images/alg.png')
@@ -122,3 +122,8 @@ def getSupportedOutputTableExtensions(self):
122122

123123
def supportsNonFileBasedOutput(self):
124124
return False
125+
126+
def tr(self, string, context=''):
127+
if context == '':
128+
context = 'AlgorithmProvider'
129+
return QtCore.QCoreApplication.translate(context, string)

python/plugins/processing/core/GeoAlgorithm.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def execute(self, progress=None, model=None):
220220
except Exception, e:
221221
# If something goes wrong and is not caught in the
222222
# algorithm, we catch it here and wrap it
223-
lines = ['Uncaught error while executing algorithm']
223+
lines = [self.tr('Uncaught error while executing algorithm')]
224224
errstring = traceback.format_exc()
225225
newline = errstring.find('\n')
226226
if newline != -1:
@@ -230,7 +230,7 @@ def execute(self, progress=None, model=None):
230230
lines.append(errstring.replace('\n', '|'))
231231
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, lines)
232232
raise GeoAlgorithmExecutionException(str(e)
233-
+ '\nSee log for more details')
233+
+ self.tr('\nSee log for more details'))
234234

235235
def runPostExecutionScript(self, progress):
236236
scriptFile = ProcessingConfig.getSetting(
@@ -262,7 +262,7 @@ def runHookScript(self, filename, progress):
262262

263263
def convertUnsupportedFormats(self, progress):
264264
i = 0
265-
progress.setText('Converting outputs')
265+
progress.setText(self.tr('Converting outputs'))
266266
for out in self.outputs:
267267
if isinstance(out, OutputVector):
268268
if out.compatible is not None:
@@ -516,15 +516,20 @@ def getPostProcessingErrorMessage(self, wrongLayers):
516516
loaded.
517517
"""
518518

519-
html = '<p>Oooops! The following output layers could not be \
520-
open</p><ul>\n'
519+
html = self.tr('<p>Oooops! The following output layers could not be '
520+
'open</p><ul>\n')
521521
for layer in wrongLayers:
522-
html += '<li>' + layer.description \
523-
+ ': <font size=3 face="Courier New" color="#ff0000">' \
524-
+ layer.value + '</font></li>\n'
525-
html += '</ul><p>The above files could not be opened, which probably \
526-
indicates that they were not correctly produced by the \
527-
executed algorithm</p>'
528-
html += '<p>Checking the log information might help you see why those \
529-
layers were not created as expected</p>'
522+
html += self.tr('<li>%s: <font size=3 face="Courier New" '
523+
'color="#ff0000">%s</font></li>\n') % \
524+
(layer.description, layer.value)
525+
html += self.tr('</ul><p>The above files could not be opened, which '
526+
'probably indicates that they were not correctly '
527+
'produced by the executed algorithm</p>'
528+
'<p>Checking the log information might help you see'
529+
'why those layers were not created as expected</p>')
530530
return html
531+
532+
def tr(self, string, context=''):
533+
if context == '':
534+
context = 'GeoAlgorithm'
535+
return QtCore.QCoreApplication.translate(context, string)

python/plugins/processing/core/Processing.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
__revision__ = '$Format:%H$'
2828

2929
import sys
30+
3031
from PyQt4.QtCore import *
3132
from PyQt4.QtGui import *
33+
3234
from qgis.core import *
33-
import processing
3435
from qgis.utils import iface
36+
37+
import processing
3538
from processing.modeler.ModelerUtils import ModelerUtils
3639
from processing.core.ProcessingConfig import ProcessingConfig
3740
from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -92,9 +95,8 @@ def addProvider(provider, updateList=False):
9295
Processing.updateAlgsList()
9396
except:
9497
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
95-
'Could not load provider:'
96-
+ provider.getDescription() + '\n'
97-
+ unicode(sys.exc_info()[1]))
98+
self.tr('Could not load provider: %s\n%s')
99+
% (provider.getDescription(), unicode(sys.exc_info()[1])))
98100
Processing.removeProvider(provider)
99101

100102
@staticmethod
@@ -281,15 +283,17 @@ def runAlgorithm(algOrName, onFinish, *args):
281283
continue
282284
print 'Error: Wrong parameter value %s for parameter %s.' \
283285
% (value, name)
284-
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error in %s. Wrong parameter value %s for parameter %s." \
286+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
287+
self.tr("Error in %s. Wrong parameter value %s for parameter %s.") \
285288
% (alg.name, value, name))
286289
return
287290
# fill any missing parameters with default values if allowed
288291
for param in alg.parameters:
289292
if param.name not in setParams:
290293
if not param.setValue(None):
291294
print ("Error: Missing parameter value for parameter %s." % (param.name))
292-
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error in %s. Missing parameter value for parameter %s." \
295+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
296+
self.tr("Error in %s. Missing parameter value for parameter %s.") \
293297
% (alg.name, param.name))
294298
return
295299
else:
@@ -343,3 +347,9 @@ def runAlgorithm(algOrName, onFinish, *args):
343347
QApplication.restoreOverrideCursor()
344348
progress.close()
345349
return alg
350+
351+
def tr(self, string, context=''):
352+
if context == '':
353+
context = 'Processing'
354+
return QtCore.QCoreApplication.translate(context, string)
355+

python/plugins/processing/core/outputs.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ def setValue(self, value):
8383
def outputTypeName(self):
8484
return self.__module__.split('.')[-1]
8585

86+
def tr(self, string, context=''):
87+
if context == '':
88+
context = 'Output'
89+
return QCoreApplication.translate(context, string)
90+
91+
8692
class OutputDirectory(Output):
8793
directory = True
8894

95+
8996
class OutputExtent(Output):
9097

9198
def __init__(self, name='', description=''):
@@ -104,6 +111,7 @@ def setValue(self, value):
104111
except:
105112
return False
106113

114+
107115
class OutputFile(Output):
108116

109117
def __init__(self, name='', description='', ext = None):
@@ -112,17 +120,18 @@ def __init__(self, name='', description='', ext = None):
112120

113121
def getFileFilter(self, alg):
114122
if self.ext is None:
115-
return 'All files(*.*)'
123+
return self.tr('All files(*.*)', 'OutputFile')
116124
else:
117-
return '%s files(*.%s)' % (self.ext, self.ext)
125+
return self.tr('%s files(*.%s)', 'OutputFile') % (self.ext, self.ext)
118126

119127
def getDefaultFileExtension(self, alg):
120128
return self.ext or 'file'
121129

130+
122131
class OutputHTML(Output):
123132

124133
def getFileFilter(self, alg):
125-
return 'HTML files(*.html)'
134+
return self.tr('HTML files(*.html)', 'OutputHTML')
126135

127136
def getDefaultFileExtension(self, alg):
128137
return 'html'
@@ -136,6 +145,7 @@ def __init__(self, name='', description=''):
136145
self.value = None
137146
self.hidden = True
138147

148+
139149
class OutputRaster(Output):
140150

141151
compatible = None
@@ -149,7 +159,7 @@ def getFileFilter(self, alg):
149159
# use extensions given by the algorithm provider
150160
exts = providerExts
151161
for i in range(len(exts)):
152-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
162+
exts[i] = self.tr('%s files(*.%s)', 'OutputRaster') % (exts[i].upper(), exts[i].lower())
153163
return ';;'.join(exts)
154164

155165
def getDefaultFileExtension(self, alg):
@@ -174,6 +184,7 @@ def getCompatibleFileName(self, alg):
174184
+ self.getDefaultFileExtension(alg))
175185
return self.compatible
176186

187+
177188
class OutputString(Output):
178189

179190
def __init__(self, name='', description=''):
@@ -182,6 +193,7 @@ def __init__(self, name='', description=''):
182193
self.value = None
183194
self.hidden = True
184195

196+
185197
class OutputTable(Output):
186198

187199
encoding = None
@@ -241,7 +253,7 @@ class OutputVector(Output):
241253
def getFileFilter(self, alg):
242254
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
243255
for i in range(len(exts)):
244-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
256+
self.tr('%s files(*.%s)', 'OutputVector') % (exts[i].upper(), exts[i].lower())
245257
return ';;'.join(exts)
246258

247259
def getDefaultFileExtension(self, alg):
@@ -287,7 +299,7 @@ def getVectorWriter(self, fields, geomType, crs, options=None):
287299

288300
if self.encoding is None:
289301
settings = QSettings()
290-
self.encoding = settings.value('/Processing/encoding', 'System', type=str)
302+
self.encoding = settings.value('/Processing/encoding', 'System', str)
291303

292304
w = VectorWriter(self.value, self.encoding, fields, geomType,
293305
crs, options)

python/plugins/processing/core/parameters.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
__revision__ = '$Format:%H$'
2828

2929
import sys
30-
from processing.tools.system import *
30+
31+
from PyQt4.QtCore import *
3132
from qgis.core import *
33+
34+
from processing.tools.system import *
3235
from processing.tools import dataobjects
3336

3437

@@ -38,6 +41,7 @@ def getParameterFromString(s):
3841
clazz = getattr(sys.modules[__name__], tokens[0])
3942
return clazz(*params)
4043

44+
4145
def parseBool(s):
4246
if s == unicode(None):
4347
return None
@@ -89,6 +93,11 @@ def parameterName(self):
8993
def todict(self):
9094
return self.__dict__
9195

96+
def tr(self, string, context=''):
97+
if context == '':
98+
context = 'Parameter'
99+
return QtCore.QCoreApplication.translate(context, string)
100+
92101

93102
class ParameterBoolean(Parameter):
94103

@@ -140,6 +149,7 @@ def getValueAsCommandLineParameter(self):
140149
else:
141150
return '"' + unicode(self.value).replace('\\', '\\\\') + '"'
142151

152+
143153
class ParameterExtent(Parameter):
144154

145155
USE_MIN_COVERING_EXTENT = 'USE_MIN_COVERING_EXTENT'
@@ -170,6 +180,7 @@ def setValue(self, text):
170180
def getValueAsCommandLineParameter(self):
171181
return '"' + unicode(self.value) + '"'
172182

183+
173184
class ParameterFile(Parameter):
174185

175186
def __init__(self, name='', description='', isFolder=False, optional=True, ext = None):
@@ -193,6 +204,7 @@ def setValue(self, obj):
193204
return self.value.endswith(self.ext)
194205
return True
195206

207+
196208
class ParameterFixedTable(Parameter):
197209

198210
def __init__(self, name='', description='', numRows=3,
@@ -348,11 +360,11 @@ def getFileFilter(self):
348360
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
349361
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
350362
elif self.datatype == ParameterMultipleInput.TYPE_FILE:
351-
return "All files (*.*)"
363+
return self.tr('All files (*.*)', 'ParameterMultipleInput')
352364
else:
353365
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
354366
for i in range(len(exts)):
355-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
367+
exts[i] = self.tr('%s files(*.%s', 'ParameterMultipleInput') % (exts[i].upper(), exts[i].lower())
356368
return ';;'.join(exts)
357369

358370

@@ -483,11 +495,10 @@ def setValue(self, obj):
483495
def getFileFilter(self):
484496
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
485497
for i in range(len(exts)):
486-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
498+
exts[i] = self.tr('%s files(*.%s', 'ParameterRaster') % (exts[i].upper(), exts[i].lower())
487499
return ';;'.join(exts)
488500

489501

490-
491502
class ParameterSelection(Parameter):
492503

493504
def __init__(self, name='', description='', options=[], default=0):
@@ -539,7 +550,6 @@ def getValueAsCommandLineParameter(self):
539550
ParameterString.ESCAPED_NEWLINE)) + '"'
540551

541552

542-
543553
class ParameterTable(ParameterDataObject):
544554

545555
def __init__(self, name='', description='', optional=False):
@@ -602,9 +612,10 @@ def getSafeExportedTable(self):
602612
def getFileFilter(self):
603613
exts = ['csv', 'dbf']
604614
for i in range(len(exts)):
605-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
615+
exts[i] = self.tr('%s files(*.%s', 'ParameterTable') % (exts[i].upper(), exts[i].lower())
606616
return ';;'.join(exts)
607617

618+
608619
class ParameterTableField(Parameter):
609620

610621
DATA_TYPE_NUMBER = 0
@@ -631,13 +642,9 @@ def setValue(self, value):
631642
return self.optional
632643
return True
633644

634-
635645
def __str__(self):
636646
return self.name + ' <' + self.__module__.split('.')[-1] + ' from ' \
637647
+ self.parent + '>'
638-
# -*- coding: utf-8 -*-
639-
640-
641648

642649

643650
class ParameterVector(ParameterDataObject):
@@ -714,5 +721,5 @@ def getSafeExportedLayer(self):
714721
def getFileFilter(self):
715722
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
716723
for i in range(len(exts)):
717-
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
724+
exts[i] = self.tr('%s files(*.%s', 'ParameterVector') % (exts[i].upper(), exts[i].lower())
718725
return ';;'.join(exts)

0 commit comments

Comments
 (0)