Skip to content

Commit 12bc030

Browse files
committed
fix: allow to translate dashboard headers
1 parent 3caa313 commit 12bc030

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ compile_translations:
8686
TUTOR_ROOT=$(TUTOR_ROOT) tutor config save
8787
python scripts/translate.py $(TUTOR_ROOT) compile
8888

89+
list_translations:
90+
TUTOR_ROOT=$(TUTOR_ROOT) tutor config save
91+
python scripts/translate.py $(TUTOR_ROOT) list
92+
8993
version: ## Print the current tutor version
9094
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("$(PACKAGE)", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
9195

scripts/translate.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import sys
33

44
import click
5-
import yaml
6-
from transifex.native import init, tx
7-
from transifex.native.parsing import SourceString
8-
from utils import LANGUAGES, compile_translations, push_translations
5+
from transifex.native import init
6+
from utils import (LANGUAGES, compile_translations, get_text_for_translations,
7+
push_translations)
98

109
init(
1110
os.getenv("TRANSIFEX_TOKEN"),
@@ -23,6 +22,8 @@ def command(root, action):
2322
push_translations(root)
2423
elif action == "compile":
2524
compile_translations(root)
25+
elif action == "list":
26+
get_text_for_translations(root)
2627
else:
2728
print("Unknown action: {}".format(action))
2829
sys.exit(1)

scripts/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def extract_text(asset, type):
5555

5656
meta = element.get("meta", {})
5757

58-
if element.get("type") == "TAB" and meta.get("text"):
58+
if meta.get("text"):
5959
strings.append(meta["text"])
6060

6161
elif type == "charts":

tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
"""Import a list of assets from a yaml file and create them in the superset assets folder."""
22
import os
33
import uuid
4-
import yaml
54
from zipfile import ZipFile
5+
6+
import yaml
67
from superset.app import create_app
78

89
app = create_app()
910
app.app_context().push()
1011

12+
from copy import deepcopy
13+
1114
from superset import security_manager
1215
from superset.commands.importers.v1.assets import ImportAssetsCommand
1316
from superset.commands.importers.v1.utils import get_contents_from_bundle
1417
from superset.extensions import db
1518
from superset.models.dashboard import Dashboard
1619
from superset.utils.database import get_or_create_db
1720

18-
from copy import deepcopy
19-
2021
BASE_DIR = "/app/assets/superset"
2122

2223
ASSET_FOLDER_MAPPING = {
@@ -37,7 +38,9 @@
3738
ASSETS_FILE_PATH = "/app/pythonpath/assets.yaml"
3839
ASSETS_ZIP_PATH = "/app/assets/assets.zip"
3940

40-
ASSETS_TRANSLATIONS = yaml.load(open(TRANSLATIONS_FILE_PATH, "r"), Loader=yaml.FullLoader)
41+
ASSETS_TRANSLATIONS = yaml.load(
42+
open(TRANSLATIONS_FILE_PATH, "r"), Loader=yaml.FullLoader
43+
)
4144

4245

4346
def main():
@@ -99,9 +102,7 @@ def write_asset_to_file(asset, asset_name, folder, file_name, roles):
99102
# access the original dashboards.
100103
dashboard_roles = asset.pop("_roles", None)
101104
if dashboard_roles:
102-
roles[asset["uuid"]] = [
103-
security_manager.find_role("Admin")
104-
]
105+
roles[asset["uuid"]] = [security_manager.find_role("Admin")]
105106

106107
path = f"{BASE_DIR}/{folder}/{file_name}.yaml"
107108
with open(path, "w") as file:
@@ -136,6 +137,8 @@ def generate_translated_dashboard_elements(copy, language):
136137
"""Generate translated elements for a dashboard"""
137138
position = copy.get("position", {})
138139

140+
SUPPORTED_TYPES = ["TAB", "HEADER"]
141+
139142
for element in position.values():
140143
if not isinstance(element, dict):
141144
continue
@@ -155,12 +158,12 @@ def generate_translated_dashboard_elements(copy, language):
155158
meta["sliceName"] = translation
156159
meta["uuid"] = element_id
157160

158-
elif element.get("type") == "TAB":
161+
elif element.get("type") in SUPPORTED_TYPES:
159162
chart_body_id = element.get("id")
160163
if not meta or not meta.get("text"):
161164
continue
162165

163-
element_type = "Tab"
166+
element_type = element.get("type")
164167
element_id = chart_body_id
165168
translation = get_translation(meta["text"], language)
166169

@@ -220,7 +223,6 @@ def update_dashboard_roles(roles):
220223
db.session.commit()
221224

222225

223-
224226
def get_translation(text, language):
225227
"""Get a translation for a text in a language"""
226228
LANGUAGE = ASSETS_TRANSLATIONS.get(language, {})

tutoraspects/templates/aspects/apps/superset/pythonpath/locale.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ de:
1717
Operator Dashboard: ''
1818
Organizations: ''
1919
Problem engagement: ''
20+
Problem engagement overview: ''
21+
Problem performance: ''
2022
Problem submission counts: ''
2123
Response distribution: ''
2224
Synchronized Courses: ''
@@ -49,6 +51,8 @@ es:
4951
Operator Dashboard: Panel de Operador
5052
Organizations: Organizaciones
5153
Problem engagement: "Participaci\xF3n en problemas"
54+
Problem engagement overview: ''
55+
Problem performance: ''
5256
Problem submission counts: "Recuento de env\xEDo de problemas"
5357
Response distribution: "Distribuci\xF3n de respuestas"
5458
Synchronized Courses: Cursos sincronizados
@@ -81,6 +85,8 @@ fr:
8185
Operator Dashboard: ''
8286
Organizations: ''
8387
Problem engagement: ''
88+
Problem engagement overview: ''
89+
Problem performance: ''
8490
Problem submission counts: ''
8591
Response distribution: ''
8692
Synchronized Courses: ''
@@ -112,6 +118,8 @@ it:
112118
Operator Dashboard: ''
113119
Organizations: ''
114120
Problem engagement: ''
121+
Problem engagement overview: ''
122+
Problem performance: ''
115123
Problem submission counts: ''
116124
Response distribution: ''
117125
Synchronized Courses: ''
@@ -143,6 +151,8 @@ ja:
143151
Operator Dashboard: ''
144152
Organizations: ''
145153
Problem engagement: ''
154+
Problem engagement overview: ''
155+
Problem performance: ''
146156
Problem submission counts: ''
147157
Response distribution: ''
148158
Synchronized Courses: ''
@@ -174,6 +184,8 @@ ko:
174184
Operator Dashboard: ''
175185
Organizations: ''
176186
Problem engagement: ''
187+
Problem engagement overview: ''
188+
Problem performance: ''
177189
Problem submission counts: ''
178190
Response distribution: ''
179191
Synchronized Courses: ''
@@ -205,6 +217,8 @@ nl:
205217
Operator Dashboard: ''
206218
Organizations: ''
207219
Problem engagement: ''
220+
Problem engagement overview: ''
221+
Problem performance: ''
208222
Problem submission counts: ''
209223
Response distribution: ''
210224
Synchronized Courses: ''
@@ -236,6 +250,8 @@ pt:
236250
Operator Dashboard: ''
237251
Organizations: ''
238252
Problem engagement: ''
253+
Problem engagement overview: ''
254+
Problem performance: ''
239255
Problem submission counts: ''
240256
Response distribution: ''
241257
Synchronized Courses: ''
@@ -267,6 +283,8 @@ ru:
267283
Operator Dashboard: ''
268284
Organizations: ''
269285
Problem engagement: ''
286+
Problem engagement overview: ''
287+
Problem performance: ''
270288
Problem submission counts: ''
271289
Response distribution: ''
272290
Synchronized Courses: ''
@@ -298,6 +316,8 @@ sk:
298316
Operator Dashboard: ''
299317
Organizations: ''
300318
Problem engagement: ''
319+
Problem engagement overview: ''
320+
Problem performance: ''
301321
Problem submission counts: ''
302322
Response distribution: ''
303323
Synchronized Courses: ''
@@ -329,6 +349,8 @@ sl:
329349
Operator Dashboard: ''
330350
Organizations: ''
331351
Problem engagement: ''
352+
Problem engagement overview: ''
353+
Problem performance: ''
332354
Problem submission counts: ''
333355
Response distribution: ''
334356
Synchronized Courses: ''
@@ -360,6 +382,8 @@ zh:
360382
Operator Dashboard: ''
361383
Organizations: ''
362384
Problem engagement: ''
385+
Problem engagement overview: ''
386+
Problem performance: ''
363387
Problem submission counts: ''
364388
Response distribution: ''
365389
Synchronized Courses: ''

0 commit comments

Comments
 (0)