From ba1be151f882ef34a66135644603355e0ab3c125 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 16:32:13 +0200 Subject: [PATCH 01/10] Refactor: return PoProjectStats from completion module --- completion.py | 14 +++++++------- generate.py | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/completion.py b/completion.py index a420b498c..6ad23233b 100644 --- a/completion.py +++ b/completion.py @@ -20,9 +20,9 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]: ] -def get_completion( +def get_stats( clones_dir: str, repo: str -) -> tuple[float, 'TranslatorsData', str, float]: +) -> tuple[potodo.PoProjectStats, 'TranslatorsData', str, float]: clone_path = Path(clones_dir, 'translations', repo) for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + [ 'master', @@ -43,15 +43,15 @@ def get_completion( translators_data = TranslatorsData(translators_number, translators_link) break path_for_merge = Path(clones_dir, 'rebased_translations', repo) - completion = potodo.merge_and_scan_path( + po_project = potodo.merge_and_scan_path( clone_path, pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=path_for_merge, hide_reserved=False, api_url='', - ).completion + ) - if completion: + if po_project.completion: # Fetch commit from before 30 days ago and checkout try: commit = next( @@ -73,9 +73,9 @@ def get_completion( else: month_ago_completion = 0.0 - change = completion - month_ago_completion + change = po_project.completion - month_ago_completion - return completion, translators_data, branch, change + return po_project, translators_data, branch, change @dataclass(frozen=True) diff --git a/generate.py b/generate.py index f773848b3..85fbb2531 100644 --- a/generate.py +++ b/generate.py @@ -7,6 +7,7 @@ from dataclasses import dataclass, asdict from datetime import datetime, timezone from pathlib import Path +from types import SimpleNamespace from git import Repo from jinja2 import Template @@ -14,7 +15,7 @@ import build_status import contribute -from completion import branches_from_devguide, get_completion, TranslatorsData +from completion import branches_from_devguide, get_stats, TranslatorsData from repositories import Language, get_languages_and_repos from word_count import get_word_count @@ -56,9 +57,9 @@ def get_project_data( ) -> 'LanguageProjectData': built = language.code in languages_built if repo: - completion, translators_data, branch, change = get_completion(clones_dir, repo) + stats, translators_data, branch, change = get_stats(clones_dir, repo) else: - completion = 0.0 + stats = SimpleNamespace(completion=0.0) translators_data = TranslatorsData(0, False) change = 0.0 branch = '' @@ -66,7 +67,7 @@ def get_project_data( language, repo, branch, - completion, + stats.completion, change, translators_data, built, From b250f038dab15a982b47e3e22edc837fbc494f7d Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 17:28:34 +0200 Subject: [PATCH 02/10] Render language data --- generate.py | 5 ++++ language.html.jinja | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 language.html.jinja diff --git a/generate.py b/generate.py index 85fbb2531..05457b124 100644 --- a/generate.py +++ b/generate.py @@ -58,6 +58,11 @@ def get_project_data( built = language.code in languages_built if repo: stats, translators_data, branch, change = get_stats(clones_dir, repo) + + template = Template(Path('language.html.jinja').read_text()) + Path(f'{language.code}.html').write_text( + template.render(stats=stats, language=language) + ) else: stats = SimpleNamespace(completion=0.0) translators_data = TranslatorsData(0, False) diff --git a/language.html.jinja b/language.html.jinja new file mode 100644 index 000000000..f04524016 --- /dev/null +++ b/language.html.jinja @@ -0,0 +1,56 @@ + + + Python Docs Translation Dashboard + + + + + + +

Python Docs Translation Dashboard: {{ language.name }}

+ + + + + + + + + +{% for directory in stats.stats_by_directory() %} + + + + +{% endfor %} + +
pathcompletion
{{ directory.path.stem }} +
+ {{ '{:.2f}%'.format(directory.completion) }} +
+
+ {{ '{:.2f}%'.format(directory.completion) }} +
+
+ + + From a8f833f116430d2be45fa6b256fe693f7c2f0708 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 17:46:58 +0200 Subject: [PATCH 03/10] Render files data --- language.html.jinja | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/language.html.jinja b/language.html.jinja index f04524016..be278272a 100644 --- a/language.html.jinja +++ b/language.html.jinja @@ -21,7 +21,7 @@ {% for directory in stats.stats_by_directory() %} - {{ directory.path.stem }} + ▶ {{ directory.path.name }} ({{ directory.files_stats | length }})
{{ '{:.2f}%'.format(directory.completion) }} @@ -31,6 +31,19 @@
+{% for file in directory.files_stats %} + + {{ file.filename }} + +
+ {{ file.percent_translated }}% +
+
+ {{ file.percent_translated }}% +
+ + +{% endfor %} {% endfor %} From f34796ac6e8bd35f5dfcd2f08de2571c775e97d8 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 21:55:53 +0200 Subject: [PATCH 04/10] Sort files in directories --- language.html.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language.html.jinja b/language.html.jinja index be278272a..14565a643 100644 --- a/language.html.jinja +++ b/language.html.jinja @@ -31,7 +31,7 @@ -{% for file in directory.files_stats %} +{% for file in directory.files_stats | sort(attribute='filename') %} {{ file.filename }} From 6f526f3b382a7252dfc23e43898949a68344e43a Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 22:04:39 +0200 Subject: [PATCH 05/10] Add number of entries --- language.html.jinja | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/language.html.jinja b/language.html.jinja index 14565a643..ebcbb2662 100644 --- a/language.html.jinja +++ b/language.html.jinja @@ -15,7 +15,7 @@ path - completion + completion* @@ -24,10 +24,10 @@ ▶ {{ directory.path.name }} ({{ directory.files_stats | length }})
- {{ '{:.2f}%'.format(directory.completion) }} + {{ '{:.2f}%'.format(directory.completion) }} ({{ directory.translated }} / {{ directory.entries }})
- {{ '{:.2f}%'.format(directory.completion) }} + {{ '{:.2f}%'.format(directory.completion) }} ({{ directory.translated }} / {{ directory.entries }})
@@ -36,10 +36,10 @@ {{ file.filename }}
- {{ file.percent_translated }}% + {{ file.percent_translated }}% ({{ file.translated }} / {{ file.entries }})
- {{ file.percent_translated }}% + {{ file.percent_translated }}% ({{ file.translated }} / {{ file.entries }})
@@ -47,6 +47,7 @@ {% endfor %} +

* in brackets: number of strings (entries) translated / total

diff --git a/style.css b/style.css index 866b7454d..5fa2d6e2d 100644 --- a/style.css +++ b/style.css @@ -53,6 +53,10 @@ td[data-label="completion"] { right: 10px; } +.directory { + cursor: pointer; +} + @media screen and (max-width: 675px) { .switchpages{ all: unset; From bf9a84873f22dc7dd1daa3d82f6fc591e586a5f7 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Fri, 16 May 2025 23:06:34 +0200 Subject: [PATCH 08/10] Make language link internal --- template.html.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.html.jinja b/template.html.jinja index 26f81aed2..5a057fae4 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -39,7 +39,7 @@ main | meta {% if project.translators.link %}{% endif %} - +
From 748a19439111b65947ecab5beda547b809334dea Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Sat, 17 May 2025 00:03:13 +0200 Subject: [PATCH 09/10] Copy over language details files in CI --- .github/workflows/update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index dbe47d6f2..0eed57858 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -21,7 +21,7 @@ jobs: - run: sudo apt-get install -y gettext - run: pip install -r requirements.txt - run: uv run generate.py # generates index.html and index.json - - run: mkdir -p build && cp index.* style.css build + - run: mkdir -p build && cp index.* style.css *.html build - name: Deploy 🚀 if: github.event_name != 'pull_request' uses: JamesIves/github-pages-deploy-action@v4 From 2778efef13a096e7fa41b83f0c3fd0d5c0b77a60 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Sun, 18 May 2025 23:15:38 +0200 Subject: [PATCH 10/10] Update update.yml for shellcheck to pass --- .github/workflows/update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 0eed57858..de577ec5e 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -21,7 +21,7 @@ jobs: - run: sudo apt-get install -y gettext - run: pip install -r requirements.txt - run: uv run generate.py # generates index.html and index.json - - run: mkdir -p build && cp index.* style.css *.html build + - run: mkdir -p build && cp index.* style.css ./*.html build - name: Deploy 🚀 if: github.event_name != 'pull_request' uses: JamesIves/github-pages-deploy-action@v4