Skip to content

Commit

Permalink
Generate HTML summary of localization status (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
flodolo authored May 3, 2024
1 parent 6247dde commit 3ee5eb0
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def main():
output.append("\nList of files not translated:")
for f in only_en_files:
output.append(f"* {f}")
stats[f] = {
"count": 0,
}

missing_en_files = list(set(stats.keys()) - set(source_filenames))
missing_en_files.sort()
Expand Down
47 changes: 47 additions & 0 deletions .github/scripts/generate_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /usr/bin/env python3

import os
import json


def main():
script_path = os.path.dirname(__file__)
root_path = os.path.abspath(os.path.join(script_path, os.pardir, os.pardir))

with open(os.path.join(root_path, ".github", "stats.json")) as f:
stats = json.load(f)

with open(os.path.join(root_path, ".github", "templates", "index.html")) as f:
html_template = f.read()

body_localized = []
body_not_localized = []
for file_name, file_stats in stats.items():
if file_stats["count"] > 0:
body_localized.append(
f"""
<tr>
<td>{file_name}</td>
<td>{file_stats['count']}</td>
<td>{', '.join(file_stats['locales'])}</td>
</tr>"""
)
else:
body_not_localized.append(
f"""
<tr>
<td>{file_name}</td>
</tr>"""
)

html_template = html_template.replace(
"%TABLEBODYLOCALIZED%", "\n".join(body_localized)
).replace("%TABLEBODYNOTLOCALIZED%", "\n".join(body_not_localized))

os.makedirs(os.path.join(root_path, "docs"), exist_ok=True)
with open(os.path.join(root_path, "docs", "index.html"), "w") as f:
f.write(html_template)


if __name__ == "__main__":
main()
19 changes: 13 additions & 6 deletions .github/scripts/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
],
"translated_docs": [
"en/acceptable_use_policy.md",
"en/amo_policies.md",
"en/common_voice_privacy_notice.md",
"en/common_voice_terms.md",
"en/content_moderation_practices.md",
"en/firefox_about_rights.md",
"en/firefox_cloud_services_tos.md",
"en/firefox_lite_contentservices_reward.md",
"en/firefox_lite_contentservices_tos.md",
"en/firefox_lite_privacy_notice.md",
"en/firefox_monitor_terms_privacy.md",
"en/firefox_os_privacy_notice.md",
"en/firefox_privacy_notice.md",
"en/firefox_relay_privacy_notice.md",
"en/firefox_relay_tos.md",
"en/focus_privacy_notice.md",
"en/mobile_partner_website_branding_terms.md",
"en/mobile_partner_website_prototype_agreement.md",
"en/hubs_privacy_notice.md",
"en/hubs_tos.md",
"en/mdn_plus_privacy.md",
"en/mdn_plus_terms.md",
"en/mozilla_accounts_privacy_notice.md",
"en/mozilla_privacy_policy.md",
"en/mozilla_vpn_privacy_notice.md",
"en/mozilla_vpn_tos.md",
"en/ossn_site_privacy_notice.md",
"en/pocket_privacy_policy.md",
"en/pocket_privacy_policy_eu.md",
"en/pocket_tos.md",
"en/report_infringement.md",
"en/subscription_services_privacy_notice.md",
"en/subscription_services_tos.md",
"en/websites_privacy_notice.md",
"en/websites_tou.md"
]
Expand Down
44 changes: 44 additions & 0 deletions .github/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>

<head>
<title>Legal Documents — Localization Summary</title>
<meta charSet="utf-8" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</head>

<body>
<div class="container">
<h1>Localized Documents</h1>
<table class="table table-striped table-bordered table-sm">
<thead class="table-dark">
<tr>
<th>Filename</th>
<th># Locales</th>
<th>Locales</th>
</tr>
</thead>
<tbody>
%TABLEBODYLOCALIZED%
</tbody>
</table>

<h1>English-only Documents</h1>
<table class="table table-striped table-bordered table-sm">
<thead class="table-dark">
<tr>
<th>Filename</th>
</tr>
</thead>
<tbody>
%TABLEBODYNOTLOCALIZED%
</tbody>
</table>
</div>
</body>

</html>
2 changes: 2 additions & 0 deletions .github/workflows/check_l10n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
python .github/scripts/check_status.py
# Only keep source files that are relevant for translation
python .github/scripts/cleanup_repository.py
# Generate HTML summary
python .github/scripts/generate_summary.py
# Use temporary folder to store files from the default branch
cd ..;mkdir temp_files
Expand Down

0 comments on commit 3ee5eb0

Please sign in to comment.