Skip to content
Permalink
Browse files

[processing] add full i18n support (still needs some work to mark all

strings as translatable)
  • Loading branch information
alexbruy committed Oct 3, 2014
1 parent 46effa1 commit f935316882656a64c255ee038043622bd7ba857a
@@ -26,7 +26,7 @@
__revision__ = '$Format:%H$'

import os
from PyQt4 import QtGui
from PyQt4 import QtGui, QtCore
from qgis.core import *
from processing.core.ProcessingConfig import Setting, ProcessingConfig

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

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

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

def supportsNonFileBasedOutput(self):
return False

def tr(self, string, context=''):
if context == '':
context = 'AlgorithmProvider'
return QtCore.QCoreApplication.translate(context, string)
@@ -220,7 +220,7 @@ def execute(self, progress=None, model=None):
except Exception, e:
# If something goes wrong and is not caught in the
# algorithm, we catch it here and wrap it
lines = ['Uncaught error while executing algorithm']
lines = [self.tr('Uncaught error while executing algorithm')]
errstring = traceback.format_exc()
newline = errstring.find('\n')
if newline != -1:
@@ -230,7 +230,7 @@ def execute(self, progress=None, model=None):
lines.append(errstring.replace('\n', '|'))
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, lines)
raise GeoAlgorithmExecutionException(str(e)
+ '\nSee log for more details')
+ self.tr('\nSee log for more details'))

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

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

html = '<p>Oooops! The following output layers could not be \
open</p><ul>\n'
html = self.tr('<p>Oooops! The following output layers could not be '
'open</p><ul>\n')
for layer in wrongLayers:
html += '<li>' + layer.description \
+ ': <font size=3 face="Courier New" color="#ff0000">' \
+ layer.value + '</font></li>\n'
html += '</ul><p>The above files could not be opened, which probably \
indicates that they were not correctly produced by the \
executed algorithm</p>'
html += '<p>Checking the log information might help you see why those \
layers were not created as expected</p>'
html += self.tr('<li>%s: <font size=3 face="Courier New" '
'color="#ff0000">%s</font></li>\n') % \
(layer.description, layer.value)
html += self.tr('</ul><p>The above files could not be opened, which '
'probably indicates that they were not correctly '
'produced by the executed algorithm</p>'
'<p>Checking the log information might help you see'
'why those layers were not created as expected</p>')
return html

def tr(self, string, context=''):
if context == '':
context = 'GeoAlgorithm'
return QtCore.QCoreApplication.translate(context, string)
@@ -27,11 +27,14 @@
__revision__ = '$Format:%H$'

import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *
import processing
from qgis.utils import iface

import processing
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -92,9 +95,8 @@ def addProvider(provider, updateList=False):
Processing.updateAlgsList()
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load provider:'
+ provider.getDescription() + '\n'
+ unicode(sys.exc_info()[1]))
self.tr('Could not load provider: %s\n%s')
% (provider.getDescription(), unicode(sys.exc_info()[1])))
Processing.removeProvider(provider)

@staticmethod
@@ -281,15 +283,17 @@ def runAlgorithm(algOrName, onFinish, *args):
continue
print 'Error: Wrong parameter value %s for parameter %s.' \
% (value, name)
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error in %s. Wrong parameter value %s for parameter %s." \
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr("Error in %s. Wrong parameter value %s for parameter %s.") \
% (alg.name, value, name))
return
# fill any missing parameters with default values if allowed
for param in alg.parameters:
if param.name not in setParams:
if not param.setValue(None):
print ("Error: Missing parameter value for parameter %s." % (param.name))
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error in %s. Missing parameter value for parameter %s." \
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr("Error in %s. Missing parameter value for parameter %s.") \
% (alg.name, param.name))
return
else:
@@ -343,3 +347,9 @@ def runAlgorithm(algOrName, onFinish, *args):
QApplication.restoreOverrideCursor()
progress.close()
return alg

def tr(self, string, context=''):
if context == '':
context = 'Processing'
return QtCore.QCoreApplication.translate(context, string)

@@ -83,9 +83,16 @@ def setValue(self, value):
def outputTypeName(self):
return self.__module__.split('.')[-1]

def tr(self, string, context=''):
if context == '':
context = 'Output'
return QCoreApplication.translate(context, string)


class OutputDirectory(Output):
directory = True


class OutputExtent(Output):

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


class OutputFile(Output):

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

def getFileFilter(self, alg):
if self.ext is None:
return 'All files(*.*)'
return self.tr('All files(*.*)', 'OutputFile')
else:
return '%s files(*.%s)' % (self.ext, self.ext)
return self.tr('%s files(*.%s)', 'OutputFile') % (self.ext, self.ext)

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


class OutputHTML(Output):

def getFileFilter(self, alg):
return 'HTML files(*.html)'
return self.tr('HTML files(*.html)', 'OutputHTML')

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


class OutputRaster(Output):

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

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


class OutputString(Output):

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


class OutputTable(Output):

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

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

if self.encoding is None:
settings = QSettings()
self.encoding = settings.value('/Processing/encoding', 'System', type=str)
self.encoding = settings.value('/Processing/encoding', 'System', str)

w = VectorWriter(self.value, self.encoding, fields, geomType,
crs, options)
@@ -27,8 +27,11 @@
__revision__ = '$Format:%H$'

import sys
from processing.tools.system import *

from PyQt4.QtCore import *
from qgis.core import *

from processing.tools.system import *
from processing.tools import dataobjects


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


def parseBool(s):
if s == unicode(None):
return None
@@ -89,6 +93,11 @@ def parameterName(self):
def todict(self):
return self.__dict__

def tr(self, string, context=''):
if context == '':
context = 'Parameter'
return QtCore.QCoreApplication.translate(context, string)


class ParameterBoolean(Parameter):

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


class ParameterExtent(Parameter):

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


class ParameterFile(Parameter):

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


class ParameterFixedTable(Parameter):

def __init__(self, name='', description='', numRows=3,
@@ -348,11 +360,11 @@ def getFileFilter(self):
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
elif self.datatype == ParameterMultipleInput.TYPE_FILE:
return "All files (*.*)"
return self.tr('All files (*.*)', 'ParameterMultipleInput')
else:
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
for i in range(len(exts)):
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
exts[i] = self.tr('%s files(*.%s', 'ParameterMultipleInput') % (exts[i].upper(), exts[i].lower())
return ';;'.join(exts)


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



class ParameterSelection(Parameter):

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



class ParameterTable(ParameterDataObject):

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


class ParameterTableField(Parameter):

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


def __str__(self):
return self.name + ' <' + self.__module__.split('.')[-1] + ' from ' \
+ self.parent + '>'
# -*- coding: utf-8 -*-




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

0 comments on commit f935316

Please sign in to comment.
You can’t perform that action at this time.