jscheffl commented on code in PR #51537:
URL: https://github.com/apache/airflow/pull/51537#discussion_r2136280830


##########
airflow-core/src/airflow/ui/src/i18n/check_translations_completeness.py:
##########
@@ -235,6 +245,123 @@ def get_outdated_entries_for_language(
     return outdated
 
 
+def count_todo_and_total(obj):
+    """Recursively count TODO: translate entries and total entries in a dict 
or list."""
+    todo = 0
+    total = 0
+    if isinstance(obj, dict):
+        for v in obj.values():
+            t, n = count_todo_and_total(v)
+            todo += t
+            total += n
+    elif isinstance(obj, list):
+        for v in obj:
+            t, n = count_todo_and_total(v)
+            todo += t
+            total += n
+    else:
+        total = 1
+        if isinstance(obj, str) and obj.strip().startswith("TODO: translate"):
+            todo = 1
+    return todo, total
+
+
+def print_translation_progress(console, locale_files, missing_counts, summary):
+    from rich.table import Table
+
+    tables = defaultdict(lambda: Table(show_lines=True))
+    all_files = set()
+    for lf in locale_files:
+        all_files.update(lf.files)
+    for lf in locale_files:
+        lang = lf.locale
+        table = tables[lang]
+        table.title = f"Translation Progress: {lang}"
+        table.add_column("File", style="bold cyan")
+        table.add_column("Missing", style="red")
+        table.add_column("Extra", style="yellow")
+        table.add_column("TODOs", style="magenta")
+        table.add_column("Translated", style="green")
+        table.add_column("Total", style="bold")
+        table.add_column("Percent", style="bold")
+        total_missing = 0
+        total_extra = 0
+        total_todos = 0
+        total_translated = 0
+        total_total = 0
+        for filename in sorted(all_files):
+            file_path = Path(LOCALES_DIR / lang / filename)
+            # Always get total from English version
+            en_path = Path(LOCALES_DIR / "en" / filename)
+            if en_path.exists():
+                with open(en_path) as f:
+                    en_data = json.load(f)
+                file_total = sum(1 for _ in flatten_keys(en_data))
+            else:
+                file_total = 0
+            if file_path.exists():
+                with open(file_path) as f:
+                    data = json.load(f)
+                file_missing = missing_counts.get(filename, {}).get(lang, 0)
+                file_extra = len(summary.get(filename, LocaleSummary({}, 
{})).extra_keys.get(lang, []))
+
+                # Count TODOs
+                def count_todos(obj):
+                    if isinstance(obj, dict):
+                        return sum(count_todos(v) for v in obj.values())
+                    if isinstance(obj, list):
+                        return sum(count_todos(v) for v in obj)
+                    if isinstance(obj, str) and obj.strip().startswith("TODO: 
translate"):
+                        return 1
+                    return 0
+
+                file_todos = count_todos(data)
+                file_translated = file_total - file_missing
+                percent = 100 * file_translated / file_total if file_total 
else 100
+                style = (
+                    "bold green"
+                    if file_missing == 0 and file_extra == 0 and file_todos == 0
+                    else (
+                        "yellow" if file_missing < file_total or file_extra > 
0 or file_todos > 0 else "red"
+                    )
+                )
+            else:
+                file_missing = file_total
+                file_extra = len(summary.get(filename, LocaleSummary({}, 
{})).extra_keys.get(lang, []))
+                file_todos = 0
+                file_translated = 0
+                percent = 0
+                style = "red"
+            table.add_row(
+                f"[bold reverse]{filename}[/bold reverse]",
+                str(file_missing),
+                str(file_extra),
+                str(file_todos),
+                str(file_translated),
+                str(file_total),
+                f"{percent:.1f}%",
+                style=style,
+            )
+            total_missing += file_missing
+            total_extra += file_extra
+            total_todos += file_todos
+            total_translated += file_translated
+            total_total += file_total
+        percent = 100 * total_translated / total_total if total_total else 100
+        table.add_row(
+            "All files",
+            str(total_missing),
+            str(total_extra),
+            str(total_todos),
+            str(total_translated),
+            str(total_total),
+            f"{percent:.1f}%",
+            style="red" if percent < 100 else "bold green",
+        )
+    for _lang, table in tables.items():

Review Comment:
   Maybe in the loop you should have skipped "en" :-D as this is always 100%



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to