Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
fix translation bug (workaround) and a translated type for csv
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Jul 24, 2019
1 parent 658440c commit d19cda7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
50 changes: 33 additions & 17 deletions land_survey_field_codes_available_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,112 @@
"""

from qgis.core import QgsMapLayerProxyModel
from PyQt5.QtCore import QCoreApplication


def tr(message):
return QCoreApplication.translate('LandSurveyFieldCodes', message)

from PyQt5.QtCore import QSettings

AVAILABLE_CODE = [
{"name": tr("Circle from 2 points"),
{"name": "Circle from 2 points",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 2,
"nbparams": 0,
"available": True,
"code": "Circle2Points"},
{"name": tr("Circle from 3 points"),
{"name": "Circle from 3 points",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 3,
"nbparams": 0,
"available": True,
"code": "Circle3Points"},
{"name": tr("Circle from center and radius"),
{"name": "Circle from center and radius",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 1,
"nbparams": 1,
"available": True,
"code": "CircleCenterRadius"},
{"name": tr("Circle from center and diameter"),
{"name": "Circle from center and diameter",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 1,
"nbparams": 1,
"available": True,
"code": "CircleCenterDiameter"},
{"name": tr("Square from 2 points"),
{"name": "Square from 2 points",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 2,
"nbparams": 0,
"available": True,
"code": "Square2Points"},
{"name": tr("Square from 2 diagonal points"),
{"name": "Square from 2 diagonal points",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 2,
"nbparams": 0,
"available": True,
"code": "Square2Diagonal"},
{"name": tr("Rectangle from 2 points and height"),
{"name": "Rectangle from 2 points and height",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 2,
"nbparams": 1,
"available": True,
"code": "Rectangle2PointsHeight"},
{"name": tr("Rectangle from 3 points (3rd point = distance)"),
{"name": "Rectangle from 3 points (3rd point = distance)",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 3,
"nbparams": 0,
"available": True,
"code": "Rectangle3PointsDistance"},
{"name": tr("Rectangle from 3 points (3rd point = projected orthogonal)"),
{"name": "Rectangle from 3 points (3rd point = projected orthogonal)",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer |
QgsMapLayerProxyModel.PointLayer,
"nbpoints": 3,
"nbparams": 0,
"available": True,
"code": "Rectangle3PointsProjected"},
{"name": tr("Line"),
{"name": "Line",
"filter": QgsMapLayerProxyModel.PolygonLayer |
QgsMapLayerProxyModel.LineLayer,
"nbpoints": -1,
"nbparams": 0,
"available": True,
"code": "Line"},
{"name": tr("Point"),
{"name": "Point",
"filter": QgsMapLayerProxyModel.PointLayer,
"nbpoints": 1,
"nbparams": 0,
"available": True,
"code": "Point"}]

TRANSLATION = {
"en" : ["Circle from 2 points","Circle from 3 points", "Circle from center and radius", "Circle from center and diameter", "Square from 2 points", "Square from 2 diagonal points","Rectangle from 2 points and height", "Rectangle from 3 points (3rd point = distance)", "Rectangle from 3 points (3rd point = projected orthogonal)", "Line","Point"],
"fr" : ["Cercle par 2 points", "Cercle par 3 points", "Cercle par le centre et le rayon", "Cercle par le centre et le diamètre", "Carré par 2 points", "Carré par 2 points en diagonale", "Rectangle par 2 points et une hauteur", "Rectangle par 3 points (3ème point = distance)", "Rectangle par 3 points (3ème point = projetée orthogonale)", "Ligne", "Point"]
}

def translatedName(name):
locale = QSettings().value('locale/userLocale')[0:2]
if locale not in TRANSLATION.keys():
locale = "en"

idx = TRANSLATION['en'].index(name)
return TRANSLATION[locale][idx]

def translatedNameFromGeometryType(geometryType):
for code in AVAILABLE_CODE:
if code['code'] == geometryType:
return translatedName(code['name'])

print("Hmmm... geometryType not found")
return geometryType
4 changes: 2 additions & 2 deletions land_survey_field_codes_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
***************************************************************************/
"""

from .land_survey_field_codes_available_code import AVAILABLE_CODE
from .land_survey_field_codes_available_code import AVAILABLE_CODE, translatedName

import os
from pathlib import Path
Expand Down Expand Up @@ -78,7 +78,7 @@ def __init__(self, parent=None):

for item in AVAILABLE_CODE:
if item['available']:
self.mGeometry.addItem(item['name'], item)
self.mGeometry.addItem(translatedName(item['name']), item)
self.__geometryChanged()

self.mLayerAllPoints.setFilters(QgsMapLayerProxyModel.PointLayer)
Expand Down
6 changes: 3 additions & 3 deletions land_survey_qlsc2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
QgsVectorLayer, QgsWkbTypes)

from .land_survey_utils import verifyCodification

from .land_survey_field_codes_available_code import translatedNameFromGeometryType

class landsurveyQLSC2CSV(QgsProcessingAlgorithm):
"""
Expand Down Expand Up @@ -84,10 +84,10 @@ def qlsc2csv(self, qlsc_path, csv_path):
codif = code['Codification']
with open(csv_path, 'w') as csv_file:
csv_writer = csv.writer(csv_file, dialect='excel-tab')
csv_writer.writerow(['code', 'source', 'pathname', 'dirname', 'basename', 'layername', 'internaltype', 'geometrytype', 'description', 'attributes'])
csv_writer.writerow(['code', 'source', 'pathname', 'dirname', 'basename', 'layername', 'internaltype', 'displaytype', 'geometrytype', 'description', 'attributes'])
for k in codif.keys():
codification = codif[k]
csv_writer.writerow([k, codification['Layer'], *(self.__explodeSource(codification['Layer'])), codification['GeometryType'], self.__geometryFromSource(codification['Layer']), codification['Description'], self.__attributesToString(codification['Attributes']) ] )
csv_writer.writerow([k, codification['Layer'], *(self.__explodeSource(codification['Layer'])), codification['GeometryType'], translatedNameFromGeometryType(codification['GeometryType']), self.__geometryFromSource(codification['Layer']), codification['Description'], self.__attributesToString(codification['Attributes']) ] )


def initAlgorithm(self, config):
Expand Down

0 comments on commit d19cda7

Please sign in to comment.