Skip to content

Commit 116f634

Browse files
Concede
1 parent daa0233 commit 116f634

File tree

6 files changed

+39
-81
lines changed

6 files changed

+39
-81
lines changed

completion.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from functools import cache
44
from pathlib import Path
55
from tempfile import TemporaryDirectory
6-
from typing import Literal, List
6+
from typing import Literal
77

88
import git
99
from potodo import potodo
@@ -36,15 +36,13 @@ def get_completion(
3636
)
3737
except git.GitCommandError:
3838
print(f'failed to clone {repo} {branch}')
39-
translators_data = TranslatorsData(0, [], False)
39+
translators_data = TranslatorsData(0, False)
4040
branch = ''
4141
continue
4242
else:
43-
translators_list, translators_number = translators.get_number(clone_path)
43+
translators_number = translators.get_number(clone_path)
4444
translators_link = translators.get_link(clone_path, repo, branch)
45-
translators_data = TranslatorsData(
46-
translators_number, translators_list, translators_link
47-
)
45+
translators_data = TranslatorsData(translators_number, translators_link)
4846
break
4947
path_for_merge = Path(clones_dir, 'rebased_translations', repo)
5048
completion = potodo.merge_and_scan_path(
@@ -85,5 +83,4 @@ def get_completion(
8583
@dataclass(frozen=True)
8684
class TranslatorsData:
8785
number: int
88-
list: List
8986
link: str | Literal[False]

generate.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_project_data(
6666
completion, translators_data, branch, change = get_completion(clones_dir, repo)
6767
else:
6868
completion = 0.0
69-
translators_data = TranslatorsData(0, [], False)
69+
translators_data = TranslatorsData(0, False)
7070
change = 0.0
7171
branch = ''
7272

@@ -127,12 +127,6 @@ class LanguageProjectData:
127127
counts=counts,
128128
)
129129

130-
lang_template = env.get_template('language.html.jinja')
131-
for project in completion_progress:
132-
code = project.language.code
133-
html = lang_template.render(project=project)
134-
Path(f'build/{code}.html').write_text(html)
135-
136130
Path('build/style.css').write_bytes(Path('src/style.css').read_bytes())
137131
Path('build/logo.png').write_bytes(Path('src/logo.png').read_bytes())
138132
Path('build/index.html').write_text(index)

templates/base.html.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<a class="nav-link" href="metadata.html">Metadata</a>
4040
</li>
4141
<li class="nav-item">
42-
<a class="nav-link" href="https://devguide.python.org/documentation/translations/translating/">Devguide ❯ Translating</a>
42+
<a class="nav-link" href="https://devguide.python.org/documentation/translations/translating/">🔗 Translating</a>
4343
</li>
4444
</ul>
4545
</div>

templates/index.html.jinja

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@
55
<div class="row">
66
{% for project in completion_progress | sort(attribute='completion,translators.number') | reverse %}
77
<div class="col-12 col-sm-6 col-md-4 d-flex">
8-
<a href="{{ project.language.code }}.html" class="card mb-3 w-100">
8+
<div class="card mb-3 w-100">
99
<div class="card-body">
10+
<h5 class="card-subtitle text-muted">{{ project.translated_name }}</h5>
1011
<h4 class="card-title">{{ project.language.name }} ({{ project.language.code }})</h4>
1112
<h5 class="card-subtitle mb-2">Completion: <strong>{{ '{:.2f}%'.format(project.completion) }}</strong></h5>
1213
<h6 class="card-subtitle mb-2 text-muted">30 Days Progress: {{ '{:.2f}%'.format(project.change) }}</h6>
1314
<h6 class="card-subtitle mb-2 text-muted">Translators: {{ project.translators.number }}</h6>
15+
<h6 style="text-align: center;">
16+
{% if project.built %}
17+
<a href="https://docs.python.org/{{ project.language.code }}/3/" style="color: #1595fe;">View</a>
18+
19+
{% endif %}
20+
{% if project.translators.link %}
21+
<a href="{{ project.translators.link }}" style="color: #1595fe;">Contribute</a>
22+
{% elif project.uses_platform %}
23+
<a href="https://app.transifex.com/join/?o=python-doc&p=python-newest&t=opensource" style="color: #1595fe;">Contribute</a>
24+
{% else %}
25+
<a href="https://devguide.python.org/documentation/translations/translating/" style="color: #1595fe;">Contribute</a>
26+
{% endif %}
27+
{% if project.repository %}
28+
29+
<a href="https://github.com/{{ project.repository }}" style="color: #1595fe;">Repository</a>
30+
{% endif %}
31+
</h6>
1432
<div class="progress-bar-container">
1533
<div class="progress-bar-index" style="width: {{ project.completion }}%;
1634
{% if project.change %}
@@ -21,7 +39,7 @@
2139
</div>
2240
</div>
2341
</div>
24-
</a>
42+
</div>
2543
</div>
2644
{% endfor %}
2745
</div>

templates/language.html.jinja

Lines changed: 0 additions & 43 deletions
This file was deleted.

translators.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
from collections.abc import Iterator
22
from pathlib import Path
3-
from re import fullmatch, sub
3+
from re import fullmatch
44
from tempfile import TemporaryDirectory
55
from typing import Literal
66

77
from git import Repo
88
from polib import pofile
99

1010

11-
def _format_translator(translator: str) -> str:
12-
translator = translator.strip()
13-
return sub(r'<.*?>', '', translator).strip()
11+
def get_number(path: Path) -> int:
12+
from_headers = len(set(yield_from_headers(path)))
13+
from_git_history = get_number_from_git_history(path)
14+
from_translators_file = len(get_from_translators_file(path))
15+
return max(from_headers, from_git_history, from_translators_file)
1416

1517

16-
def get_number(path: Path) -> tuple[list, int]:
17-
from_po_headers = set(yield_from_headers(path))
18-
from_git_history = set(get_from_git_history(path))
19-
from_translators_file = set(get_from_translators_file(path))
20-
largest_set = max(from_po_headers, from_git_history, from_translators_file)
21-
return list(largest_set), len(largest_set)
22-
23-
24-
def get_from_git_history(path: Path) -> list[str]:
25-
raw_lines = Repo(path).git.shortlog('-s', 'HEAD').splitlines()
26-
return [_format_translator(line.split('\t', 1)[-1]) for line in raw_lines]
18+
def get_number_from_git_history(path: Path) -> int:
19+
return len(Repo(path).git.shortlog('-s', 'HEAD').splitlines())
2720

2821

2922
def yield_from_headers(path: Path) -> Iterator[str]:
@@ -38,17 +31,16 @@ def yield_from_headers(path: Path) -> Iterator[str]:
3831
try:
3932
translator, _year = translator_record.split(', ')
4033
except ValueError:
41-
translator = translator_record
42-
if translator.strip() == 'Transifex Bot <>':
43-
continue
44-
yield _format_translator(translator)
34+
yield translator_record
35+
else:
36+
yield translator
4537

4638

4739
def get_from_translators_file(path: Path) -> list[str]:
4840
if not (file := path.joinpath('TRANSLATORS')).exists():
4941
return []
5042
return list(
51-
_format_translator(line)
43+
line
5244
for line in file.read_text().splitlines()
5345
if line != 'Translators'
5446
and not fullmatch(r'-*', line)
@@ -80,7 +72,7 @@ def get_link(clone_path: Path, repo: str, branch: str) -> str | Literal[False]:
8072
branch=branch,
8173
)
8274
from_headers = len(set(yield_from_headers(path := Path(directory))))
83-
from_git_history = get_from_git_history(path)
75+
from_git_history = get_number_from_git_history(path)
8476
from_translators_file = len(get_from_translators_file(path))
8577
print(
8678
f'{lang}: {from_headers=}, {from_git_history=}, {from_translators_file=}'

0 commit comments

Comments
 (0)