Skip to content

Commit

Permalink
Get release translations
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Jun 19, 2024
1 parent a5d51b7 commit eb50c95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
11 changes: 11 additions & 0 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ def get_appstream(
number = int(key.split("_")[-1])
value["screenshots"][number]["caption"] = translation[key]

if key.startswith("release_description_"):
number = int(key.split("_")[-1])
value["releases"][number]["description"] = translation[key]

translation = {
k: v
for k, v in translation.items()
if not k.startswith("screenshots_caption_")
and not k.startswith("release_description_")
}

return value | translation
else:
return value
Expand Down
38 changes: 26 additions & 12 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,39 @@ def appstream2dict(appstream_url=None) -> tuple[dict[str, dict], dict[str, dict]
releases = component.find("releases")
if releases is not None:
app["releases"] = []
for rel in releases:
for i, keyword in enumerate(releases):
attrs = {}
for attr in rel.attrib:
attrs[attr] = rel.attrib[attr]

desc = rel.find("description")
if desc is not None:
description = [
etree.tostring(tag, encoding=("unicode")) for tag in desc
]
attrs["description"] = "".join(description)
for attr in keyword.attrib:
attrs[attr] = keyword.attrib[attr]

descs = keyword.findall("description")
for desc in descs:
if desc is not None:
description = [
etree.tostring(tag, encoding=("unicode")) for tag in desc
]
if (
desc.attrib.get(
"{http://www.w3.org/XML/1998/namespace}lang"
)
is None
):
attrs["description"] = "".join(description)
else:
add_translation(
apps_locale,
desc.get("{http://www.w3.org/XML/1998/namespace}lang"),
appid,
"release_description_" + str(i),
"".join(description),
)

url = rel.find("url")
url = keyword.find("url")
if url is not None:
attrs["url"] = url.text

app["releases"].append(attrs.copy())
component.remove(releases)

content_rating = component.find("content_rating")
if content_rating is not None:
app["content_rating"] = {}
Expand Down

0 comments on commit eb50c95

Please sign in to comment.