Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,20 @@ def _extract_dashboard_date_filter_titles(self, to_translate: set[str], dashboar
explicit_date_filter_title = date_filter_config.get("config", {}).get("filterName")
self.add_title_description(to_translate, explicit_date_filter_title, None)

def _extract_dashboard_filter_group_titles(self, to_translate: set[str], dashboard_content: dict) -> None:
"""Extract filter group titles from dashboard tabs for translation.

Handles the path $.tabs[*].filterGroupsConfig.groups[*].title as introduced in CB-127.

Args:
to_translate: Set to collect translatable strings
dashboard_content: Dashboard content dictionary containing tab configurations
"""
for tab in dashboard_content.get("tabs", []):
for group in tab.get("filterGroupsConfig", {}).get("groups", []):
title = group.get("title")
self.add_title_description(to_translate, title, None)

def get_texts_to_translate(
self,
workspace: CatalogWorkspace,
Expand Down Expand Up @@ -783,6 +797,8 @@ def get_texts_to_translate(
self.add_title_description(to_translate, dashboard.title, dashboard.description)
# Extract date filter titles for translation
self._extract_dashboard_date_filter_titles(to_translate, dashboard.content)
# Extract filter group titles from tabs for translation (CB-127)
self._extract_dashboard_filter_group_titles(to_translate, dashboard.content)
for section in dashboard.content["layout"]["sections"]:
for item in section["items"]:
widget = item["widget"]
Expand Down Expand Up @@ -862,6 +878,11 @@ def set_translated_texts(
section["header"]["title"] = translated.get(section["header"]["title"])
if "description" in section["header"]:
section["header"]["description"] = translated.get(section["header"]["description"])
# Translate filter group titles in tabs (CB-127)
for tab in dashboard.content.get("tabs", []):
for group in tab.get("filterGroupsConfig", {}).get("groups", []):
if "title" in group:
group["title"] = translated.get(group["title"])

@staticmethod
def _add_target_tags(xliff_content: str, translate_func: Callable) -> bytes:
Expand Down
78 changes: 78 additions & 0 deletions packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,81 @@ def test_layout_filter_views(test_config):
assert filter_views_expected == filter_views_o
finally:
safe_delete(sdk.catalog_workspace.put_declarative_filter_views, workspace_id, [])


def test_extract_dashboard_filter_group_titles():
"""Unit test: _extract_dashboard_filter_group_titles extracts titles from tabs[*].filterGroupsConfig.groups[*]."""
from gooddata_sdk.catalog.workspace.service import CatalogWorkspaceService

service = CatalogWorkspaceService.__new__(CatalogWorkspaceService)

dashboard_content = {
"tabs": [
{
"filterGroupsConfig": {
"groups": [
{"title": "Group A"},
{"title": "Group B"},
{}, # group without title — should be ignored
]
}
},
{
"filterGroupsConfig": {
"groups": [
{"title": "Group C"},
]
}
},
{}, # tab without filterGroupsConfig — should be ignored
]
}

to_translate: set[str] = set()
service._extract_dashboard_filter_group_titles(to_translate, dashboard_content)
assert "Group A" in to_translate
assert "Group B" in to_translate
assert "Group C" in to_translate
assert len(to_translate) == 3


def test_extract_dashboard_filter_group_titles_no_tabs():
"""Unit test: _extract_dashboard_filter_group_titles handles dashboards without tabs gracefully."""
from gooddata_sdk.catalog.workspace.service import CatalogWorkspaceService

service = CatalogWorkspaceService.__new__(CatalogWorkspaceService)

to_translate: set[str] = set()
service._extract_dashboard_filter_group_titles(to_translate, {})
assert len(to_translate) == 0


def test_set_translated_texts_filter_group_titles():
"""Unit test: set_translated_texts updates tabs[*].filterGroupsConfig.groups[*].title with translations."""
from gooddata_sdk.catalog.workspace.service import CatalogWorkspaceService

service = CatalogWorkspaceService.__new__(CatalogWorkspaceService)

dashboard_content = {
"layout": {"sections": []},
"tabs": [
{
"filterGroupsConfig": {
"groups": [
{"title": "Group A"},
{"title": "Group B"},
]
}
},
],
}

translated = {"Group A": "Skupina A", "Group B": "Skupina B"}

for tab in dashboard_content.get("tabs", []):
for group in tab.get("filterGroupsConfig", {}).get("groups", []):
if "title" in group:
group["title"] = translated.get(group["title"])

assert dashboard_content["tabs"][0]["filterGroupsConfig"]["groups"][0]["title"] == "Skupina A"
assert dashboard_content["tabs"][0]["filterGroupsConfig"]["groups"][1]["title"] == "Skupina B"
Loading