@@ -38,32 +38,24 @@ def deep_merge(d1, d2):
38
38
class QGSReader :
39
39
""" Read QGIS projects and extract data for QWC config """
40
40
41
- def __init__ (self , config , logger , assets_dir , translations_dir , use_cached_project_metadata , global_print_layouts ):
41
+ def __init__ (self , config , logger , assets_dir , use_cached_project_metadata , global_print_layouts ):
42
42
"""Constructor
43
43
44
44
:param obj config: Config generator config
45
45
:param Logger logger: Application logger
46
46
:param string assets_dir: Assets directory
47
- :param str translations_dir: Viewer translations directory
48
47
:param bool use_cached_project_metadata: Whether to use cached project metadata
49
48
:param list global_print_layouts: Global print layouts
50
49
"""
51
50
self .config = config
52
51
self .logger = logger
53
52
self .assets_dir = assets_dir
54
- self .translations_dir = translations_dir
55
53
self .use_cached_project_metadata = use_cached_project_metadata
56
54
self .global_print_layouts = global_print_layouts
57
55
58
56
self .qgs_resources_path = config .get ('qgis_projects_base_dir' , '/tmp/' )
59
57
self .qgs_ext = config .get ('qgis_project_extension' , '.qgs' )
60
58
self .nested_nrels = config .get ('generate_nested_nrel_forms' , False )
61
- try :
62
- with open (os .path .join (self .translations_dir , 'tsconfig.json' )) as fh :
63
- self .viewer_languages = json .load (fh )['languages' ]
64
- except :
65
- self .logger .warning ("Failed to detect viewer languages from tsconfig.json" )
66
- self .viewer_languages = ["en-US" ]
67
59
68
60
self .db_engine = DatabaseEngine ()
69
61
@@ -147,20 +139,15 @@ def read(self, map_prefix, theme_item, edit_datasets):
147
139
148
140
# Build layername -> shortname lookup
149
141
shortname_map = {}
150
- id_name_map = {}
151
142
for maplayer in root .findall ('.//maplayer' ):
152
143
layernameEl = maplayer .find ('layername' )
153
144
if layernameEl is not None :
154
145
shortnameEl = maplayer .find ('shortname' )
155
- idEl = maplayer .find ('id' )
156
146
shortname = shortnameEl .text if shortnameEl is not None else layernameEl .text
157
147
shortname_map [layernameEl .text ] = shortname
158
- if idEl is not None :
159
- id_name_map [idEl .text ] = shortname
160
148
161
149
return {
162
150
"project_crs" : self .__project_crs (root ),
163
- "translations" : self .__theme_translations (qgs_dir , projectname , id_name_map ),
164
151
"print_templates" : self .__print_templates (root , shortname_map ),
165
152
"visibility_presets" : self .__visibility_presets (root ),
166
153
"layer_metadata" : self .__layer_metadata (root , shortname_map , map_prefix , edit_datasets , theme_item , qgs_dir ),
@@ -172,76 +159,6 @@ def __project_crs(self, root):
172
159
authid = root .find ('./projectCrs/spatialrefsys/authid' )
173
160
return authid .text if authid is not None else None
174
161
175
- def __theme_translations (self , qgs_dir , projectname , id_name_map ):
176
- """ Read theme portion of translations from <projectname>_<lang>.json. """
177
- all_translations = {}
178
-
179
- for language in self .viewer_languages :
180
- translations = {}
181
-
182
- ts_file = os .path .join (qgs_dir , f"{ projectname } _{ language } .ts" )
183
- if not os .path .exists (ts_file ):
184
- ts_file = os .path .join (qgs_dir , f"{ projectname } _{ language [0 :2 ]} .ts" )
185
- if os .path .exists (ts_file ):
186
- self .logger .info ('Reading project translations %s' % ts_file )
187
- try :
188
- ts_document = ElementTree .parse (ts_file )
189
-
190
- # Build translation string lookup
191
- for context in ts_document .findall ("./context" ):
192
- context_name = context .find ('./name' )
193
- if context_name is None :
194
- continue
195
-
196
- context_name_parts = context_name .text .split (":" )
197
- key = None
198
- if len (context_name_parts ) >= 3 and context_name_parts [0 ] == "project" and context_name_parts [1 ] == "layers" :
199
- # replace layer id with layer name
200
- layername = id_name_map [context_name_parts [2 ]]
201
-
202
- if len (context_name_parts ) == 3 :
203
- ts_path = f"layertree"
204
- key = layername
205
- elif len (context_name_parts ) == 4 and context_name_parts [3 ] == "fieldaliases" :
206
- ts_path = f"layers.{ layername } .fields"
207
- elif len (context_name_parts ) == 4 and context_name_parts [3 ] == "formcontainers" :
208
- ts_path = f"layers.{ layername } .form"
209
- elif len (context_name_parts ) == 2 and context_name_parts [0 ] == "project" and context_name_parts [1 ] == "layergroups" :
210
- ts_path = f"layertree"
211
- else :
212
- # Unknown ts context
213
- continue
214
-
215
- context_ts = translations
216
- for entry in ts_path .split ("." ):
217
- context_ts [entry ] = context_ts .get (entry , {})
218
- context_ts = context_ts [entry ]
219
-
220
- for message in context .findall ("./message" ):
221
- source = message .find ('./source' )
222
- translation = message .find ('./translation' )
223
- if source is not None and translation is not None and translation .get ('type' , '' ) != "unfinished" :
224
- context_ts [key or source .text ] = translation .text
225
-
226
- except Exception as e :
227
- self .logger .info ('Failed to auxiliary project translations %s: %s' % (ts_file , str (e )))
228
-
229
- json_file = os .path .join (qgs_dir , f"{ projectname } _{ language } .json" )
230
- if not os .path .exists (json_file ):
231
- json_file = os .path .join (qgs_dir , f"{ projectname } _{ language [0 :2 ]} .json" )
232
- if os .path .exists (json_file ):
233
- self .logger .info ('Reading auxiliary project translations %s' % json_file )
234
- try :
235
- with open (json_file ) as fh :
236
- translations = deep_merge (translations , json .load (fh ))
237
- except Exception as e :
238
- self .logger .info ('Failed to read auxiliary project translations %s: %s' % (json_file , str (e )))
239
-
240
- if translations :
241
- all_translations [language ] = translations
242
-
243
- return all_translations
244
-
245
162
def __print_templates (self , root , shortname_map ):
246
163
""" Collect print templates from QGS and merge with global print layouts. """
247
164
0 commit comments