Skip to content

Commit

Permalink
Add Outdated Translation Checker workflow (#2205)
Browse files Browse the repository at this point in the history
* 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
gdams committed Sep 15, 2023
1 parent 7c21d9f commit e9c1684
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 7 deletions.
185 changes: 185 additions & 0 deletions .github/workflows/locale-checker.py
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()
30 changes: 30 additions & 0 deletions .github/workflows/locale-checker.yml
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
1 change: 1 addition & 0 deletions content/asciidoc-pages/about/index.zh-CN.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= About Eclipse Adoptium(R)
:page-authors: zdtsw, gdams
:page-based-on: 50e5dbed709fcbf4e2b5f225c9da68a17ebb301e

Eclipse Adoptium 作为顶级项目的使命是生产高质量的 Java 运行时和相关技术,以应用于 Java 生态系统。

Expand Down
6 changes: 3 additions & 3 deletions content/asciidoc-pages/docs/faq/index.de.adoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
= Frequently Asked Questions
:page-authors: gdams, HanSolo, sw-fox, aumann, hendrikebbers, xavierfacq
:page-based-on: 56f8f9b0dd04a8cadd21fa9b68ee86430949c0b7
:page-based-on: 7ca352f4545cad6fd03722c9206d31da76063d4a

Auf dieser Seite haben wir versucht häufig gestellte Fragen (FAQs) für die Community zu beantworten.
Alle weiteren Fragen können jederzeit gerne in unsere https://adoptium.net/slack.html[Slack-Channel] gestellt
oder per Ticket im https://github.com/adoptium/adoptium-support[Support-Kanal] eingereicht werden.

== Wo kann man die neuesten Adoptium® JDKs finden?
== Wo kann man die neuesten Adoptium(R) JDKs finden?

Die JDKs von Adoptium heißen Eclipse Temurin. Die von uns empfohlenen Versionen kann man direkt
https://adoptium.net/temurin/releases/[auf unserer Seite] finden.
Expand All @@ -19,7 +19,7 @@ von Cloud-Anbietern zu verwenden.

Linux-Installationsprogramme sind unter `packages.adoptium.net` verfügbar. Weitere Informationen hierzu finden Sie https://adoptium.net/installation/linux[in diesem Leitfaden].

== Gibt es statische Links für Temurin Builds?
== Gibt es statische Links für Temurin(TM) Builds?

Das https://github.com/adoptium/api.adoptium.net/blob/main/docs/cookbook.adoc#example-two-linking-to-the-latest-jdk-or-jre[Adoptium API cookbook] beinhatet Beispiele zu statischen und stabilen URLs die zu spezifischen Temurin Versionen verlinken. Zusätzlich bieten wir https://adoptium.net/en-GB/temurin/buttons/[HTML Buttons] an, die auf Temurin downloads verweisen.

Expand Down
1 change: 1 addition & 0 deletions content/asciidoc-pages/docs/faq/index.fr.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Frequently Asked Questions
:page-authors: xavierfacq
:page-based-on: 56f8f9b0dd04a8cadd21fa9b68ee86430949c0b7

Nous avons rassemblé quelques questions fréquemment posées (FAQ) dans ce document.
Si vous souhaitez nous parler de ces sujets ou poser des questions supplémentaires,
Expand Down
5 changes: 3 additions & 2 deletions content/asciidoc-pages/docs/qvs-policy/index.de.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:orgname: Eclipse Adoptium
:lang: en
:page-authors: gdams, HanSolo, hendrikebbers, xavierfacq
:page-based-on: 50dc526fadcdd7dd03b386f112ac1ab4043bb554
:page-based-on: edd131f41d548b815a7edbcf59848b8161fbc9e6

== Überblick

Expand All @@ -21,7 +21,8 @@ at no charge as open source licensed software. Sie können die AQAvit-Software g

Nominierte
https://github.com/adoptium/aqa-tests/releases[Versionen der AQAvit Qualitätstestsuite^]
(QVS) sind verfügbar unter der Eclipse Foundation Quality Verification Suite License (QVSL). Ein Softwareprodukt gilt als von der AQAvit QVS "verifiziert", wenn es alle Anforderungen der AQAvit QVS, wie in der QVSL beschrieben, vollständig erfüllt und einhält.
(QVS) sind verfügbar unter der
https://www.eclipse.org/legal/eclipse-foundation-quality-verification-suite-license.php[Eclipse Foundation Quality Verification Suite License^] (QVSL). Ein Softwareprodukt gilt als von der AQAvit QVS "verifiziert", wenn es alle Anforderungen der AQAvit QVS, wie in der QVSL beschrieben, vollständig erfüllt und einhält.

Es ist nicht notwendig, ein Mitglied der Adoptium-Arbeitsgruppe zu sein, um ein AQAvit-geprüftes Softwareprodukt zu erstellen.

Expand Down
1 change: 0 additions & 1 deletion content/asciidoc-pages/temurin/buttons/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
= Temurin(TM) Download Buttons

:page-authors: tellison, gdams
:keywords: buttons

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Commercial Support Options for Eclipse Temurin(TM)
:page-authors: gdams, tellison, hendrikebbers
:page-based-on: 4f7e0d66e577a9c619e38c6d670d86f9c4736874

Es gibt verschiedene kommerzielle Supportoptionen für Eclipse Temurin. Bitte beachten Sie, dass keiner der folgenden Anbieter vom Adoptium(R) Projekt evaluiert wurde oder offiziell empfohlen wird. Jeder kommerzielle Supportanbieter hat in der Regel unterschiedliche Schwerpunkte und Anwendungsfälle für seine Produkte. Daher wird empfohlen, jede Option sorgfältig im Hinblick auf Ihre spezifischen Bedürfnisse und Anforderungen hin zu evaluieren.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Commercial Support Options for Eclipse Temurin(TM)
:page-authors: gdams, tellison, hendrikebbers
:page-based-on: 4f7e0d66e577a9c619e38c6d670d86f9c4736874

Actualmente, hay disponible una variedad de opciones comerciales para el soporte de Eclipse Temurin. Es importante señalar que ninguno de estos proveedores ha sido evaluado ni cuenta con el respaldo oficial del proyecto Adoptium(R). Cada proveedor de soporte comercial tiende a atender diferentes casos de uso típicos, por lo que se recomienda que investigue cuidadosamente cada opción en función de sus necesidades y requisitos específicos.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Commercial Support Options for Eclipse Temurin(TM)
:page-authors: zdtsw, tellison
:page-based-on: 4f7e0d66e577a9c619e38c6d670d86f9c4736874

对于Eclipse Temurin,我们提供多种商业支持选项。
需要注意的是,以下列举的供应商并未经过Adoptium(R)项目的评估,也没有得到Adoptium(R)项目正式认可。
Expand Down
2 changes: 1 addition & 1 deletion locales/de/asciidoc.json
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."
}

0 comments on commit e9c1684

Please sign in to comment.