-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Outdated Translation Checker workflow (#2205)
* add shasums * Add shasum to content/asciidoc-pages/temurin/commercial-support/index.de.adoc * add tool * linter fixes * linter fixes * fixup * review changes
- Loading branch information
Showing
11 changed files
with
227 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import os | ||
import re | ||
import subprocess | ||
|
||
CONTENT_DIR = "content/asciidoc-pages" | ||
REPO = "adoptium/adoptium.net" | ||
|
||
# List of locale leads for each locale | ||
locale_leads = { | ||
"de": "@hendrikebbers", | ||
"fr": "@xavierfacq", | ||
"zh-CN": "@zdtsw", | ||
} | ||
|
||
|
||
def get_shasum(file_path): | ||
if not os.path.exists(file_path): | ||
return None | ||
with open(file_path, "r") as f: | ||
content = f.read() | ||
match = re.search(r":page-based-on:\s+(\S+)", content) | ||
return match.group(1) if match else None | ||
|
||
|
||
def get_shasum_from_git(file_path): | ||
shasum = None | ||
if os.path.exists(file_path): | ||
shasum = os.popen(f"git log -1 --format=%H {file_path}").read().strip() | ||
return shasum | ||
|
||
|
||
def addLocalizedShasum(english_shasum, locale, root): | ||
# Add the shasum to the localized file | ||
localized_file = os.path.join(root, f"index.{locale}.adoc") | ||
with open(localized_file, "r") as f: | ||
content = f.read() | ||
match = re.search(r":page-based-on:\s+(\S+)", content) | ||
if match: | ||
print(f"Updating {localized_file} with shasum {english_shasum}") | ||
content = content.replace(match.group(1), english_shasum) | ||
with open(localized_file, "w") as f: | ||
f.write(content) | ||
else: | ||
print(f"Adding shasum {english_shasum} to {localized_file}") | ||
with open(localized_file, "r") as f: | ||
content = f.readlines() | ||
|
||
# Find the line number where ':page-authors:' exists | ||
line_number = next( | ||
( | ||
index | ||
for index, line in enumerate(content) | ||
if ":page-authors:" in line | ||
), | ||
None, | ||
) | ||
|
||
# Insert shasum after the line with ':page-authors:' | ||
if line_number is not None: | ||
content.insert(line_number + 1, f":page-based-on: {english_shasum}\n") | ||
|
||
# Write the updated content back to the file | ||
with open(localized_file, "w") as f: | ||
f.writelines(content) | ||
|
||
|
||
def main(): | ||
for root, _, files in os.walk(CONTENT_DIR): | ||
english_file = os.path.join(root, "index.adoc") | ||
|
||
if "index.adoc" not in files: | ||
continue | ||
|
||
english_shasum = get_shasum_from_git(english_file) | ||
if not english_shasum: | ||
continue | ||
|
||
outdated_locales = [] | ||
|
||
localized_file_pattern = re.compile(r"^index\..+\.adoc$") | ||
for localized_file in files: | ||
if localized_file_pattern.match(localized_file): | ||
file_path = os.path.join( | ||
root.replace(".index.adoc", ""), localized_file | ||
) | ||
local_shasum = get_shasum(file_path) | ||
|
||
if local_shasum != english_shasum: | ||
locale = localized_file.split(".")[1] | ||
outdated_locales.append(locale) | ||
|
||
if outdated_locales: | ||
# Print the list of outdated locales | ||
print(f"Outdated locales for {english_file}: {outdated_locales}") | ||
# Check if an issue already exists for this file | ||
check_issue = ( | ||
os.popen( | ||
# split this line into two to avoid a bug in the GitHub CLI | ||
"gh issue list " | ||
+ f"-R {REPO} " | ||
+ "--search 'Translation review required after updates to " | ||
+ f"{os.path.relpath(english_file, CONTENT_DIR)}' " | ||
+ "--state open" | ||
) | ||
.read() | ||
.strip() | ||
) | ||
if check_issue: | ||
print(f"An issue already exists for {english_file}: {check_issue}") | ||
continue | ||
|
||
# Create an issue for this file | ||
print(f"Creating issue for {english_file}") | ||
|
||
title = f"Translation review required after updates to {os.path.relpath(english_file, CONTENT_DIR)}" | ||
|
||
body = "The English version of this file has been updated. " | ||
body += "The following localised versions are potentially out of date:\n\n" | ||
body += "```diff\n" | ||
body += f"- {english_shasum} (English latest)\n" | ||
for locale in outdated_locales: | ||
localized_shasum = get_shasum( | ||
os.path.join(root, f"index.{locale}.adoc") | ||
) | ||
# If localized file is None then we need to create a pull request to add the shasum to the file | ||
if localized_shasum is None: | ||
addLocalizedShasum(english_shasum, locale, root) | ||
# Add localized shasum to outdated_locales | ||
outdated_locales[ | ||
outdated_locales.index(locale) | ||
] = f"{localized_shasum} {locale}" | ||
body += f"+ {localized_shasum} ({locale})\n" | ||
body += "```\n\n" | ||
body += "View the Latest version of the file " | ||
body += f"[here](https://github.com/{REPO}/blob/main/{english_file}).\n\n" | ||
body += "| Locale | File | Locale Lead |\n" | ||
body += "| ------ | ---- | ----------- |\n" | ||
for locale in outdated_locales: | ||
localized_shasum = locale.split()[0].strip() | ||
locale = locale.split()[1].strip() | ||
# get locale lead | ||
locale_lead = locale_leads.get(locale) | ||
if locale_lead is None: | ||
locale_lead = "n/a" | ||
url = f"https://github.com/{REPO}/blob/main/{os.path.join(root, f'index.{locale}.adoc')}" | ||
body += ( | ||
f'| {locale} | [{f"index.{locale}.adoc"}]({url}) | {locale_lead}\n' | ||
) | ||
body += "\n" | ||
body += "---\n\n" | ||
|
||
for locale in outdated_locales: | ||
localized_shasum = locale.split()[0].strip() | ||
locale = locale.split()[1].strip() | ||
body += f"### View the changes to the English file since the last {locale} update\n\n" | ||
body += "<details>\n" | ||
body += "<summary>View Diff</summary>\n\n" | ||
# Generate diff between English file and the English version of the localized file | ||
body += "```diff\n" | ||
body += os.popen( | ||
f"git diff {localized_shasum}..{english_shasum} -- {english_file}" | ||
).read() | ||
body += "```\n\n" | ||
body += "</details>\n\n" | ||
|
||
# Generate Issue | ||
subprocess.run( | ||
[ | ||
"gh", | ||
"issue", | ||
"create", | ||
"--repo", | ||
REPO, | ||
"--title", | ||
title, | ||
"--body", | ||
body, | ||
"--label", | ||
"translation,help wanted", | ||
] | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Locale Checker | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: [ content/asciidoc-pages/** ] | ||
branches: [ main ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
|
||
jobs: | ||
locale-checker: | ||
if: github.repository_owner == 'adoptium' | ||
name: Check Locales for Changes | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Check asciidoc docs | ||
run: python3 .github/workflows/locale-checker.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
= Temurin(TM) Download Buttons | ||
|
||
:page-authors: tellison, gdams | ||
:keywords: buttons | ||
|
||
|
1 change: 1 addition & 0 deletions
1
content/asciidoc-pages/temurin/commercial-support/index.de.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
content/asciidoc-pages/temurin/commercial-support/index.es.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
content/asciidoc-pages/temurin/commercial-support/index.zh-CN.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"asciidoc.template.warn.default.locale": "Dies ist die <englishVersionLink>englische Version</englishVersionLink> der Seite, da aktuell noch keine deutsche Übersetzung verfügbar ist. Du kannst uns helfen diese Seite in deutsch bereitzustellen. In unserem <translationGuideLink>Leitfaden zu Übersetzungen</translationGuideLink> findest du mehr Informationen.", | ||
"asciidoc.template.warn.outdated": "Die deutsche Übersetzung dieser Seite basiert auf einem <previousEnglishVersionLink>nicht mehr aktuellen englischen Text</previousEnglishVersionLink>. Daher ist es Möglich, dass Teile des Textes nicht mehr zutreffen. Du kannst helfen die Seite aktuell zu halten und eine überarbeitete Übersetzung der <lastEnglishVersionLink>aktuellen englischen Seite/lastEnglishVersionLink> bereitzustellen. In unserem <translationGuideLink>Leitfaden zu Übersetzungen</translationGuideLink> findest du mehr Informationen." | ||
"asciidoc.template.warn.outdated": "Die deutsche Übersetzung dieser Seite basiert auf einem <previousEnglishVersionLink>nicht mehr aktuellen englischen Text</previousEnglishVersionLink>. Daher ist es Möglich, dass Teile des Textes nicht mehr zutreffen. Du kannst helfen die Seite aktuell zu halten und eine überarbeitete Übersetzung der <lastEnglishVersionLink>aktuellen englischen Seite</lastEnglishVersionLink> bereitzustellen. In unserem <translationGuideLink>Leitfaden zu Übersetzungen</translationGuideLink> findest du mehr Informationen." | ||
} |