Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ednote and associations description text fields in translated macro [SDNTB-875] #517

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from 2 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
18 changes: 18 additions & 0 deletions server/ntb/macros/nob_NO_translate_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ def nob_NO_translate_macro(item, **kwargs):
"description_html",
"description_text",
"evolvedfrom",
"ednote",
)
}

# extract associations description_text from the item associations structure.
associations_desc_flat = {
f"associations_desc_{editor}": assoc["description_text"]
for editor, assoc in item.get("associations", {}).items()
if "description_text" in assoc
}

payload.update(associations_desc_flat)

data = {
"token": token,
"document": payload,
Expand All @@ -45,6 +55,14 @@ def nob_NO_translate_macro(item, **kwargs):
if r.status_code == 200:
response = r.json()
item.update(response["document"])

# map translated `description_text` fields back to the associations.
for editor in item.get("associations", {}):
flat_key = f"associations_desc_{editor}"
if flat_key in response["document"]:
item["associations"][editor]["description_text"] = response["document"][
flat_key
]
return item


Expand Down