Skip to content

Commit c7b3841

Browse files
committed
Processing translation tool for names and groups
1 parent cc1a34f commit c7b3841

File tree

4 files changed

+108
-10
lines changed

4 files changed

+108
-10
lines changed

python/plugins/processing/gui/AlgorithmClassification.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828
import os
29+
from PyQt4.QtCore import QCoreApplication
2930

3031
displayNames = {}
3132
classification = {}
@@ -45,7 +46,7 @@ def loadClassification():
4546
raise Exception(line)
4647
line = lines.readline().strip('\n')
4748
lines.close()
48-
49+
4950
def loadDisplayNames():
5051
global displayNames
5152
if not os.path.isfile(displayNamesFile()):
@@ -67,12 +68,23 @@ def classificationFile():
6768
def displayNamesFile():
6869
return os.path.join(os.path.dirname(__file__), 'algnames.txt')
6970

70-
def getClassification(alg):
71+
def getClassificationEn(alg):
7172
if alg.commandLineName().lower() in classification:
7273
group, subgroup = classification[alg.commandLineName()]
7374
return group, subgroup
7475
else:
7576
return None, None
76-
77+
78+
def getClassification(alg):
79+
group, subgroup = getClassificationEn(alg)
80+
return (QCoreApplication.translate('AlgorithmClassification', group),
81+
QCoreApplication.translate('AlgorithmClassification', subgroup))
82+
83+
def getDisplayNameEn(alg):
84+
return displayNames.get(alg.commandLineName().lower(), alg.name)
85+
7786
def getDisplayName(alg):
78-
return displayNames.get(alg.commandLineName().lower(), alg.name)
87+
return QCoreApplication.translate(alg.__class__.__name__, getDisplayNameEn(alg))
88+
89+
def getDisplayGroup(group):
90+
return QCoreApplication.translate('AlgorithmClassification', group)

python/plugins/processing/gui/ProcessingToolbox.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,9 @@ def populate(self):
388388
groupItem = groups[alg.group]
389389
else:
390390
groupItem = QTreeWidgetItem()
391-
groupItem.setText(0, alg.group)
392-
groupItem.setToolTip(0, alg.group)
391+
name = AlgorithmClassification.getDisplayGroup(alg.group)
392+
groupItem.setText(0, name)
393+
groupItem.setToolTip(0, name)
393394
groups[alg.group] = groupItem
394395
algItem = TreeAlgorithmItem(alg)
395396
groupItem.addChild(algItem)

python/plugins/processing/modeler/ModelerDialog.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,9 @@ def fillAlgorithmTreeUsingCategories(self):
526526
groupItem = groups[alg.group]
527527
else:
528528
groupItem = QTreeWidgetItem()
529-
groupItem.setText(0, alg.group)
530-
groupItem.setToolTip(0, alg.group)
529+
name = AlgorithmClassification.getDisplayGroup(alg.group)
530+
groupItem.setText(0, name)
531+
groupItem.setToolTip(0, name)
531532
groups[alg.group] = groupItem
532533
algItem = TreeAlgorithmItem(alg)
533534
groupItem.addChild(algItem)
@@ -565,8 +566,9 @@ def fillAlgorithmTreeUsingProviders(self):
565566
groupItem = groups[alg.group]
566567
else:
567568
groupItem = QTreeWidgetItem()
568-
groupItem.setText(0, alg.group)
569-
groupItem.setToolTip(0, alg.group)
569+
name = AlgorithmClassification.getDisplayGroup(alg.group)
570+
groupItem.setText(0, name)
571+
groupItem.setToolTip(0, name)
570572
groups[alg.group] = groupItem
571573
algItem = TreeAlgorithmItem(alg)
572574
groupItem.addChild(algItem)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
classification.py
6+
---------------------
7+
Date : July 2015
8+
Copyright : (C) 2015 by Arnaud Morvan
9+
Email : arnaud dot morvan at camptocamp dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Arnaud Morvan'
21+
__date__ = 'July 2015'
22+
__copyright__ = '(C) 2015, Arnaud Morvan'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
import os
27+
from processing.core.Processing import Processing
28+
from processing.gui.AlgorithmClassification import (
29+
loadClassification, loadDisplayNames, getClassificationEn, getDisplayNameEn)
30+
31+
32+
def updateTranslations():
33+
"""Update processing.algs.translations module.
34+
35+
Need QGIS python API on python path, can be run from QGIS console. Example:
36+
37+
from processing.tools.translation import updateTranslations
38+
updateTranslations()
39+
"""
40+
41+
loadClassification()
42+
loadDisplayNames()
43+
44+
f = open(os.path.join(os.path.dirname(__file__), '../algs/translations.py'), 'w')
45+
f.write('''# -*- coding: utf-8 -*-
46+
47+
"""
48+
Don't edit this file manually.
49+
Update it from QGIS console:
50+
51+
from processing.tools.translation import updateTranslations
52+
updateTranslations()
53+
"""
54+
55+
from PyQt4.QtCore import QCoreApplication
56+
57+
def translationShadow():
58+
''')
59+
groups = {}
60+
for provider in Processing.providers:
61+
f.write('''
62+
"""{}"""
63+
'''.format(provider.__class__.__name__))
64+
for alg in provider.algs:
65+
display_name = getDisplayNameEn(alg)
66+
f.write(" QCoreApplication.translate(\"{}\", \"{}\")\n"
67+
.format(alg.__class__.__name__,
68+
display_name.replace('"', '\\"')))
69+
if not alg.group in groups:
70+
groups[alg.group] = 'AlgorithmClassification'
71+
group, subgroup = getClassificationEn(alg)
72+
if group is not None and not group in groups:
73+
groups[group] = 'AlgorithmClassification'
74+
if subgroup is not None and not subgroup in groups:
75+
groups[subgroup] = 'AlgorithmClassification'
76+
77+
f.write('''
78+
"""Groups and subgroups"""
79+
''')
80+
for group, context in groups.iteritems():
81+
f.write(" QCoreApplication.translate(\"{}\", \"{}\")\n"
82+
.format(context,
83+
group.replace('"', '\\"')))

0 commit comments

Comments
 (0)