]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
⚒️ Update translate script, show and update outdated translations (#13933)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 26 Jul 2025 21:27:35 +0000 (23:27 +0200)
committerGitHub <noreply@github.com>
Sat, 26 Jul 2025 21:27:35 +0000 (21:27 +0000)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
requirements-translations.txt
scripts/translate.py

index 7a2a8004e82f34ff06bdbf4ce99b4503230e3ed3..90f7180325e9d8ba2d33d21b614856d8828a3054 100644 (file)
@@ -1 +1,2 @@
 pydantic-ai==0.0.30
+GitPython==3.1.45
index 6af12dc98c22424224ae4bd56609f1730b5fd7fa..b78d7211be1b24d5b7f1161c9f678f8d7204be39 100644 (file)
@@ -2,6 +2,7 @@ from functools import lru_cache
 from pathlib import Path
 from typing import Iterable
 
+import git
 import typer
 import yaml
 from pydantic_ai import Agent
@@ -243,5 +244,39 @@ def remove_all_removable() -> None:
     print("Done removing all removable paths")
 
 
+@app.command()
+def list_outdated(lang: str) -> list[Path]:
+    dir_path = Path(__file__).absolute().parent.parent
+    repo = git.Repo(dir_path)
+
+    outdated_paths: list[Path] = []
+    en_lang_paths = list(iter_en_paths_to_translate())
+    for path in en_lang_paths:
+        lang_path = generate_lang_path(lang=lang, path=path)
+        if not lang_path.exists():
+            outdated_paths.append(path)
+            continue
+        en_commit_datetime = list(repo.iter_commits(paths=path, max_count=1))[
+            0
+        ].committed_datetime
+        lang_commit_datetime = list(repo.iter_commits(paths=lang_path, max_count=1))[
+            0
+        ].committed_datetime
+        if lang_commit_datetime < en_commit_datetime:
+            outdated_paths.append(path)
+    print(outdated_paths)
+    return outdated_paths
+
+
+@app.command()
+def update_outdated(lang: str) -> None:
+    outdated_paths = list_outdated(lang)
+    for path in outdated_paths:
+        print(f"Updating lang: {lang} path: {path}")
+        translate_page(lang=lang, path=path)
+        print(f"Done updating: {path}")
+    print("Done updating all outdated paths")
+
+
 if __name__ == "__main__":
     app()