Skip to content

Commit a35e5db

Browse files
committed
Add translated changelog optional and fix linting errors by casting to str
1 parent a0b53f8 commit a35e5db

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

_validate/createJson.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,28 @@ def _createDataclassMatchingJsonSchema(
109109
# Add optional fields
110110
homepage = manifest.get("url")
111111
changelog = manifest.get("changelog")
112-
translations: list[dict[str, str | None]] = []
112+
translations: list[dict[str, str]] = []
113113
for langCode, translatedManifest in getAddonManifestLocalizations(manifest):
114114
try:
115115
translations.append(
116116
{
117117
"language": langCode,
118118
"displayName": cast(str, translatedManifest["summary"]),
119119
"description": cast(str, translatedManifest["description"]),
120-
"changelog": translatedManifest["changelog"],
121120
},
122121
)
123122
except KeyError as e:
124123
raise KeyError(f"Translation for {langCode} missing required key '{e.args[0]}'.") from e
125124

125+
# Add optional translated changelog.
126+
translatedChangelog = translatedManifest.get("changelog")
127+
if translatedChangelog:
128+
translations.append(
129+
{
130+
"changelog": cast(str, translatedChangelog),
131+
},
132+
)
133+
126134
addonData = AddonData(
127135
addonId=cast(str, manifest["name"]),
128136
displayName=cast(str, manifest["summary"]),
@@ -139,8 +147,8 @@ def _createDataclassMatchingJsonSchema(
139147
publisher=publisher,
140148
sourceURL=sourceUrl,
141149
license=licenseName,
142-
homepage=homepage,
143-
changelog=changelog,
150+
homepage=cast(str, homepage),
151+
changelog=cast(str, changelog),
144152
licenseURL=licenseUrl,
145153
submissionTime=getCurrentTime(),
146154
translations=translations,

_validate/regenerateTranslations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ def regenerateJsonFile(filePath: str, errorFilePath: str | None) -> None:
3434
"language": langCode,
3535
"displayName": manifest["summary"],
3636
"description": manifest["description"],
37-
"changelog": changelog,
3837
},
3938
)
4039

40+
translatedChangelog = manifest.get("changelog")
41+
if translatedChangelog:
42+
addonData["translations"].append(
43+
{
44+
"changelog": translatedChangelog,
45+
},
46+
)
47+
4148
with open(filePath, "wt", encoding="utf-8") as f:
4249
json.dump(addonData, f, indent="\t", ensure_ascii=False)
4350
print(f"Wrote json file: {filePath}")

0 commit comments

Comments
 (0)