Skip to content

Commit

Permalink
feat: allow to translate markdown elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 4, 2023
1 parent 938d9df commit ceaf898
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 80 deletions.
6 changes: 5 additions & 1 deletion scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def extract_text(asset, type):
if meta.get("text"):
strings.append(meta["text"])

if meta.get("code"):
strings.append(meta["code"])

elif type == "charts":
strings.append(asset["slice_name"])
elif type == "databases":
Expand Down Expand Up @@ -101,9 +104,10 @@ def compile_translations(root_path):
translation = tx.get_translation(string, language, None)
translations[language][string] = translation if translation else ""

file.write("---\n")
file.write(yaml.dump(translations))

file.write("{{ patch('superset-extra-asset-translations')}}\n")
file.write("\n{{ patch('superset-extra-asset-translations')}}\n")


def push_translations(root_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
ASSETS_ZIP_PATH = "/app/assets/assets.zip"

merged_data = {}
with open(TRANSLATIONS_FILE_PATH, 'r') as file:
with open(TRANSLATIONS_FILE_PATH, "r") as file:
yaml_content = file.read()
yaml_documents = yaml_content.split('\n---\n')
yaml_documents = yaml_content.split("\n---\n")

for doc in yaml_documents:
data = yaml.safe_load(doc)
if data is not None:
Expand Down Expand Up @@ -149,7 +149,7 @@ def generate_translated_dashboard_elements(copy, language):
"""Generate translated elements for a dashboard"""
position = copy.get("position", {})

SUPPORTED_TYPES = ["TAB", "HEADER"]
SUPPORTED_TYPES = {"TAB": "text", "HEADER": "text", "MARKDOWN": "code"}

for element in position.values():
if not isinstance(element, dict):
Expand All @@ -170,16 +170,17 @@ def generate_translated_dashboard_elements(copy, language):
meta["sliceName"] = translation
meta["uuid"] = element_id

elif element.get("type") in SUPPORTED_TYPES:
elif element.get("type") in SUPPORTED_TYPES.keys():
text_key = SUPPORTED_TYPES.get(element["type"])
chart_body_id = element.get("id")
if not meta or not meta.get("text"):
if not meta or not meta.get(text_key):
continue

element_type = element.get("type")
element_id = chart_body_id
translation = get_translation(meta["text"], language)
translation = get_translation(meta[text_key], language)

meta["text"] = translation
meta[text_key] = translation

if translation and element_type and element_id:
print(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
de:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -8,12 +9,10 @@ de:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -25,13 +24,9 @@ de:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
es:
Actor IDs over time: IDs de actores a lo largo del tiempo
Attempts to first success: "Intentos de primer \xE9xito"
Expand All @@ -42,13 +37,11 @@ es:
Enrollment events per day: "Eventos de inscripci\xF3n por d\xEDa"
Event type: Tipo de evento
Events per course: Eventos por curso
Events per day: "Eventos por d\xEDa"
Hints and answers displayed per correct answer: Sugerencias y respuestas mostradas
por respuesta correcta
Instructor dashboard: Panel del Instructor
Last course syncronized: "\xDAltimo curso sincronizado"
Last received xAPI events: "\xDAltimo evento xAPI recibido"
Open edX Admin Dashboard: Panel de Administracion de Open edX
Operator Dashboard: Panel de Operador
Organizations: Organizaciones
Problem engagement: "Participaci\xF3n en problemas"
Expand All @@ -61,13 +54,9 @@ es:
\ por video"
Unique actors: "Actores \xFAnicos"
Video engagement: "Participaci\xF3n en videos"
Video events: "Eventos de V\xEDdeo"
Watched video segments: Segmentos de video vistos
Watches per video: "Vistas por v\xEDdeo"
xAPI events: Eventos xAPI
xAPI events by course: Eventos xAPI por curso
xAPI problem events by block: Eventos de problema xAPI por bloque
---
fr:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -78,12 +67,10 @@ fr:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -95,13 +82,9 @@ fr:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
it:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -112,12 +95,10 @@ it:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -129,13 +110,9 @@ it:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
ja:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -146,12 +123,10 @@ ja:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -163,13 +138,9 @@ ja:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
ko:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -180,12 +151,10 @@ ko:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -197,13 +166,9 @@ ko:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
nl:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -214,12 +179,10 @@ nl:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -231,13 +194,9 @@ nl:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
pt:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -248,12 +207,10 @@ pt:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -265,13 +222,9 @@ pt:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
ru:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -282,12 +235,10 @@ ru:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -299,13 +250,9 @@ ru:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
sk:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -316,12 +263,10 @@ sk:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -333,13 +278,9 @@ sk:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
sl:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -350,12 +291,10 @@ sl:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -367,13 +306,9 @@ sl:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''
---
zh:
Actor IDs over time: ''
Attempts to first success: ''
Expand All @@ -384,12 +319,10 @@ zh:
Enrollment events per day: ''
Event type: ''
Events per course: ''
Events per day: ''
Hints and answers displayed per correct answer: ''
Instructor dashboard: ''
Last course syncronized: ''
Last received xAPI events: ''
Open edX Admin Dashboard: ''
Operator Dashboard: ''
Organizations: ''
Problem engagement: ''
Expand All @@ -401,10 +334,8 @@ zh:
Transcript/closed captioning usage per video: ''
Unique actors: ''
Video engagement: ''
Video events: ''
Watched video segments: ''
Watches per video: ''
xAPI events: ''
xAPI events by course: ''
xAPI problem events by block: ''

{{ patch('superset-extra-asset-translations')}}

0 comments on commit ceaf898

Please sign in to comment.