Skip to content

Language details #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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
from urllib3 import PoolManager

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

Expand Down Expand Up @@ -56,17 +57,22 @@ 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)

template = Template(Path('language.html.jinja').read_text())
Path(f'{language.code}.html').write_text(
template.render(stats=stats, language=language)
)
else:
completion = 0.0
stats = SimpleNamespace(completion=0.0)
translators_data = TranslatorsData(0, False)
change = 0.0
branch = ''
return LanguageProjectData(
language,
repo,
branch,
completion,
stats.completion,
change,
translators_data,
built,
Expand Down
88 changes: 88 additions & 0 deletions language.html.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<html lang="en">
<head>
<title>Python Docs Translation Dashboard</title>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<meta name="description" content="Python Docs Translation Dashboard">
<base target="_blank">
</head>
<body>
<h1>Python Docs Translation Dashboard: {{ language.name }}</h1>
<nav class="switchpages">
<a href="index.html" target="_self">main</a> | <a href="metadata.html" target="_self">meta</a>
</nav>
<table>
<thead>
<tr>
<th>path</th>
<th>completion*</th>
</tr>
</thead>
{% for directory in stats.stats_by_directory() %}
<tr class="directory" data-toggle="directory-{{ loop.index }}">
<td>▶ {{ directory.path.name }} ({{ directory.files_stats | length }})</td>
<td data-label="completion">
<div class="progress-bar" style="width: {{ directory.completion }}%;background-color: #4caf50;">
{{ '{:.2f}%'.format(directory.completion) }} ({{ directory.translated }} / {{ directory.entries }})
</div>
<div class="progress-bar-outer-label">
{{ '{:.2f}%'.format(directory.completion) }} ({{ directory.translated }} / {{ directory.entries }})
</div>
</td>
</tr>
<tbody class="files" id="directory-{{ loop.index }}" style="display: none;">
{% for file in directory.files_stats | sort(attribute='filename') %}
<tr>
<td>{{ file.filename }}</td>
<td data-label="completion">
<div class="progress-bar" style="width: {{ file.percent_translated }}%;background-color: #4caf50;">
{{ file.percent_translated }}% ({{ file.translated }} / {{ file.entries }})
</div>
<div class="progress-bar-outer-label">
{{ file.percent_translated }}% ({{ file.translated }} / {{ file.entries }})
</div>
</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
<p>* in brackets: number of strings (entries) translated / total</p>
</body>
<script>
function updateProgressBarVisibility() {
document.querySelectorAll('.progress-bar').forEach(progressBar => {
const barWithOverflowWidth = progressBar.scrollWidth;
const barWidth = progressBar.clientWidth;

if (barWidth < barWithOverflowWidth) {
progressBar.classList.add('low');
} else {
progressBar.classList.remove('low');
}
});
}

updateProgressBarVisibility();

window.addEventListener('resize', updateProgressBarVisibility);

document.querySelectorAll('.directory').forEach(directoryRow => {
directoryRow.addEventListener('click', () => {
const toggleId = directoryRow.getAttribute('data-toggle');
const filesTable = document.getElementById(toggleId);
const arrow = directoryRow.querySelector('td:first-child');

if (filesTable.style.display === 'none') {
filesTable.style.display = 'table-row-group';
arrow.textContent = arrow.textContent.replace('▶', '▼');
} else {
filesTable.style.display = 'none';
arrow.textContent = arrow.textContent.replace('▼', '▶');
}

updateProgressBarVisibility();
});
});
</script>
</html>
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ td[data-label="completion"] {
right: 10px;
}

.directory {
cursor: pointer;
}

@media screen and (max-width: 675px) {
.switchpages{
all: unset;
Expand Down
2 changes: 2 additions & 0 deletions template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ main | <a href="metadata.html" target="_self">meta</a>
{% if project.translators.link %}</a>{% endif %}
</td>
<td data-label="completion">
<a href="{{ project.language.code }}.html" target="_self">
<div class="progress-bar"
style="width: {{ project.completion }}%;{% if project.change %}background: linear-gradient(to left, #94cf96 {{ project.change * 100 / project.completion }}%, #4caf50 {{ project.change * 100 / project.completion }}%);{% else %}background-color: #4caf50;{% endif %}"
>
Expand All @@ -47,6 +48,7 @@ main | <a href="metadata.html" target="_self">meta</a>
<div class="progress-bar-outer-label">
{{ '{:.2f}%'.format(project.completion) }} {% if project.change >= 0.01 %}({{ '{:+.2f}%'.format(project.change) }}){% endif %}
</div>
</a>
</td>
</tr>
{% endfor %}
Expand Down
Loading