Skip to content

Commit 292e445

Browse files
use default language for Metadata and Resources dict
1 parent 280df83 commit 292e445

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

ui_widgets/UiSetter.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
fill_combo_box,
2929
pack_locales_data_into_list,
3030
pack_list_data_into_list_widget,
31+
get_default_language,
3132
)
3233
from .utils import get_widget_text_value, reset_widget
3334

@@ -239,22 +240,27 @@ def set_ui_from_data(self):
239240
# incoming type: possible list of strings or dictionary
240241
# limitation: even if YAML had just a list of strings, it will be interpreted here as "en" locale by default
241242

243+
default_language = get_default_language(config_data)
244+
242245
# title
243246
pack_locales_data_into_list(
244247
config_data.metadata.identification.title,
245248
self.dialog.listWidgetMetadataIdTitle,
249+
default_language,
246250
)
247251

248252
# description
249253
pack_locales_data_into_list(
250254
config_data.metadata.identification.description,
251255
self.dialog.listWidgetMetadataIdDescription,
256+
default_language,
252257
)
253258

254259
# keywords
255260
pack_locales_data_into_list(
256261
config_data.metadata.identification.keywords,
257262
self.dialog.listWidgetMetadataIdKeywords,
263+
default_language,
258264
)
259265
set_combo_box_value_from_data(
260266
combo_box=self.dialog.comboBoxMetadataIdKeywordsType,
@@ -336,6 +342,7 @@ def refresh_resources_list_ui(self):
336342
def set_resource_ui_from_data(self, res_data: ResourceConfigTemplate):
337343
"""Set values for Resource UI from resource data."""
338344
dialog = self.dialog
345+
config_data: ConfigData = self.dialog.config_data
339346

340347
# first, reset some fields to defaults (e.g. for data setting, or optional - they might not have a new value to overwrite it)
341348
# data entry fields
@@ -364,20 +371,23 @@ def set_resource_ui_from_data(self, res_data: ResourceConfigTemplate):
364371
value=res_data.type,
365372
)
366373

374+
# data with locales
375+
default_language = get_default_language(config_data)
376+
367377
# title
368378
pack_locales_data_into_list(
369-
res_data.title,
370-
dialog.listWidgetResTitle,
379+
res_data.title, dialog.listWidgetResTitle, default_language
371380
)
372381

373382
# description
374383
pack_locales_data_into_list(
375-
res_data.description,
376-
dialog.listWidgetResDescription,
384+
res_data.description, dialog.listWidgetResDescription, default_language
377385
)
378386

379387
# keywords
380-
pack_locales_data_into_list(res_data.keywords, dialog.listWidgetResKeywords)
388+
pack_locales_data_into_list(
389+
res_data.keywords, dialog.listWidgetResKeywords, default_language
390+
)
381391

382392
# visibility
383393
set_combo_box_value_from_data(

ui_widgets/ui_setter_utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,30 @@ def _apply_red_transparent_style(layer):
7676
layer.triggerRepaint()
7777

7878

79-
def pack_locales_data_into_list(data, list_widget):
79+
def get_default_language(config_data) -> str:
80+
"""Get the default language from ConfigData (server.language or server.languages)."""
81+
if config_data.server.language is not None:
82+
return config_data.server.language.value.split("-")[0]
83+
84+
if config_data.server.languages is not None:
85+
for lang in config_data.server.languages: # list
86+
return lang.split("-")[0]
87+
88+
return "en"
89+
90+
91+
def pack_locales_data_into_list(data, list_widget, default_language="en"):
8092
"""Use ConfigData (list of strings, dict with strings, or a single string) to fill the UI widget list."""
8193
list_widget.clear()
8294

8395
# data can be string, list or dict (for properties like title, description, keywords)
8496
if isinstance(data, str):
8597
if is_valid_string(data):
86-
value = f"en: {data}"
98+
value = f"{default_language}: {data}"
8799
list_widget.addItem(value)
88100
return
89101

102+
# 'data' can be a list (iterating through values) or dict (iterating through keys)
90103
for key in data:
91104
if isinstance(data, dict):
92105
local_key_content = data[key]
@@ -101,7 +114,7 @@ def pack_locales_data_into_list(data, list_widget):
101114
list_widget.addItem(value)
102115
elif isinstance(data, list): # list of strings
103116
if is_valid_string(key):
104-
value = f"en: {key}"
117+
value = f"{default_language}: {key}"
105118
list_widget.addItem(value)
106119

107120

0 commit comments

Comments
 (0)