Skip to content

Commit ec11556

Browse files
committed
Drop README recreation in favor of Cog (#30)
* Switch to cog-powered README * Use cog in GitHub Actions * Make public functions public
1 parent cf33f1f commit ec11556

File tree

4 files changed

+25
-79
lines changed

4 files changed

+25
-79
lines changed

.github/workflows/update-lint-and-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
python-version: 3
2121
- run: sudo apt-get install -y gettext
22-
- run: pip install requests
22+
- run: pip install requests cogapp
2323
- uses: actions/checkout@master
2424
with:
2525
ref: ${{ matrix.version }}
@@ -31,7 +31,7 @@ jobs:
3131
- run: ./manage_translation.py fetch
3232
env:
3333
TX_TOKEN: ${{ secrets.TX_TOKEN }}
34-
- run: ./manage_translation.py recreate_readme
34+
- run: cog -rP README.md
3535
env:
3636
TX_TOKEN: ${{ secrets.TX_TOKEN }}
3737
- run: git config --local user.email github-actions@github.com

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.tx/api-key
2+
__pycache__/*

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
Polskie tłumaczenie dokumentacji Pythona
22
========================================
3+
<!-- [[[cog
4+
from manage_translation import get_resource_language_stats, progress_from_resources, language_switcher, get_number_of_translators
5+
6+
stats = get_resource_language_stats()
7+
switcher = progress_from_resources(stats, language_switcher)
8+
total = progress_from_resources(stats, lambda _: True)
9+
translators = get_number_of_translators()
10+
11+
print(
12+
f'''![build](https://github.com/python/python-docs-pl/workflows/.github/workflows/update-and-build.yml/badge.svg)
13+
![{switcher:.2f}% przełącznika języków](https://img.shields.io/badge/przełącznik_języków-{switcher:.2f}%25-0.svg)
14+
![postęp tłumaczenia całości dokumentacji](https://img.shields.io/badge/całość-{total:.2f}%25-0.svg)
15+
![{translators} tłumaczy](https://img.shields.io/badge/tłumaczy-{translators}-0.svg)''')
16+
]]] -->
317
![build](https://github.com/python/python-docs-pl/workflows/.github/workflows/update-and-build.yml/badge.svg)
418
![48.35% przełącznika języków](https://img.shields.io/badge/przełącznik_języków-48.35%25-0.svg)
519
![postęp tłumaczenia całości dokumentacji](https://img.shields.io/badge/całość-3.51%25-0.svg)
620
![19 tłumaczy](https://img.shields.io/badge/tłumaczy-19-0.svg)
21+
<!-- [[[end]]] -->
722

823
Jeśli znalazłeś(-aś) błąd lub masz sugestię,
924
[dodaj zgłoszenie](https://github.com/python/python-docs-pl/issues) w tym projekcie lub

manage_translation.py

+7-77
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#
1010
# * fetch: fetch translations from transifex.com and strip source lines from the
1111
# files.
12-
# * recreate_readme: recreate readme to update translation progress.
1312
# * regenerate_tx_config: recreate configuration for all resources.
1413

1514
from argparse import ArgumentParser
@@ -153,22 +152,22 @@ def _get_resources() -> list[Resource]:
153152
return [Resource.from_api_v3_entry(entry) for entry in resources]
154153

155154

156-
def _get_resource_language_stats() -> list[ResourceLanguageStatistics]:
155+
def get_resource_language_stats() -> list[ResourceLanguageStatistics]:
157156
resources = _get_from_api_v3_with_cursor(
158157
'https://rest.api.transifex.com/resource_language_stats',
159158
{'filter[project]': f'o:python-doc:p:{PROJECT_SLUG}', 'filter[language]': f'l:{LANGUAGE}'}
160159
)
161160
return [ResourceLanguageStatistics.from_api_v3_entry(entry) for entry in resources]
162161

163162

164-
def _progress_from_resources(resources: list[ResourceLanguageStatistics], filter_function: Callable):
163+
def progress_from_resources(resources: list[ResourceLanguageStatistics], filter_function: Callable) -> float:
165164
filtered = filter(filter_function, resources)
166165
pairs = ((e.translated_words, e.total_words) for e in filtered)
167166
translated_total, total_total = (sum(counts) for counts in zip(*pairs))
168167
return translated_total / total_total * 100
169168

170169

171-
def _get_number_of_translators():
170+
def get_number_of_translators():
172171
process = run(
173172
['grep', '-ohP', r'(?<=^# )(.+)(?=, \d+$)', '-r', '.'],
174173
capture_output=True,
@@ -179,82 +178,13 @@ def _get_number_of_translators():
179178
return len(unique_translators)
180179

181180

182-
def recreate_readme():
183-
def language_switcher(entry: ResourceLanguageStatistics) -> bool:
184-
language_switcher_resources_prefixes = ('bugs', 'tutorial', 'library--functions')
185-
return any(entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes)
186-
187-
resources = _get_resource_language_stats()
188-
language_switcher_status = _progress_from_resources(resources, language_switcher)
189-
total_progress_status = _progress_from_resources(resources, lambda _: True)
190-
number_of_translators = _get_number_of_translators()
191-
192-
with open('README.md', 'w') as file:
193-
file.write(
194-
f'''\
195-
Polskie tłumaczenie dokumentacji Pythona
196-
========================================
197-
![build](https://github.com/python/python-docs-pl/workflows/.github/workflows/update-and-build.yml/badge.svg)
198-
![{language_switcher_status:.2f}% przełącznika języków](https://img.shields.io/badge/przełącznik_języków-{language_switcher_status:.2f}%25-0.svg)
199-
![postęp tłumaczenia całości dokumentacji](https://img.shields.io/badge/całość-{total_progress_status:.2f}%25-0.svg)
200-
![{number_of_translators} tłumaczy](https://img.shields.io/badge/tłumaczy-{number_of_translators}-0.svg)
201-
202-
Jeśli znalazłeś(-aś) błąd lub masz sugestię,
203-
[dodaj zgłoszenie](https://github.com/python/python-docs-pl/issues) w tym projekcie lub
204-
napraw go sam(a):
205-
206-
* Zarejestruj się na platformie [Transifex](https://www.transifex.com/) i wejdź na stronę
207-
projektu [dokumentacji Pythona](https://www.transifex.com/python-doc/python-newest/).
208-
* Na stronie projektu wybierz język polski.
209-
* Naciśnij przycisk „Join this Team”, aby dołączyć do zespołu.
210-
* Po dołączeniu do zespołu, wybierz zasób, który chcesz poprawić/zaktualizować.
211-
212-
Więcej informacji o używaniu Transifeksa znajdziesz w
213-
[jego dokumentacji](https://docs.transifex.com/getting-started-1/translators).
214-
215-
**Postęp tłumaczenia**
216-
217-
![postęp tłumaczenia do przełącznika języków](language-switcher-progress.svg)
218-
219-
Język polski pojawi się w przełączniku języków na docs.python.org,
220-
[kiedy w pełni przetłumaczone będą](https://www.python.org/dev/peps/pep-0545/#add-translation-to-the-language-switcher):
221-
* `bugs`,
222-
* wszystkie zasoby z katalogu `tutorial`,
223-
* `library/functions`.
224-
225-
**Jak obejrzeć najnowszy build dokumentacji?**
226-
227-
Pobierz ostatnią zbudowaną dokumentację z listy artefaktów w ostatniej GitHub Action (zakładka Actions).
228-
Tłumaczenia pobierane są z Transifeksa do tego repozytorium co około pół godziny.
229-
Dokumentacja na python.org aktualizowana jest około raz dziennie.
230-
231-
**Kanały komunikacji**
232-
233-
* [python-docs-pl Discord](https://discord.gg/3faJmGKhta)
234-
* [Python translations working group](https://mail.python.org/mailman3/lists/translation.python.org/)
235-
* [Python Documentation Special Interest Group](https://www.python.org/community/sigs/current/doc-sig/)
236-
237-
**Licencja**
238-
239-
Zapraszając do współtworzenia projektu na platformie Transifex, proponujemy umowę na
240-
przekazanie twoich tłumaczeń Python Software Foundation
241-
[na licencji CC0](https://creativecommons.org/publicdomain/zero/1.0/deed.pl).
242-
W zamian będzie widoczne, że jesteś tłumaczem(-ką) części, którą przetłumaczyłeś(-łaś).
243-
Wyrażasz akceptację tej umowy przesyłając swoją pracę do włączenia do dokumentacji.
244-
245-
**Aktualizacja tłumaczeń**
246-
* `./manage_translation.py recreate_tx_config`
247-
* `./manage_translation.py fetch`
248-
* `./manage_translation.py recreate_readme`
249-
250-
**Potencjalnie przydatne materiały**
251-
* [polskie tłumaczenie dokumentacji Pythona 2.3](https://pl.python.org/docs/).
252-
'''
253-
)
181+
def language_switcher(entry: ResourceLanguageStatistics) -> bool:
182+
language_switcher_resources_prefixes = ('bugs', 'tutorial', 'library--functions')
183+
return any(entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes)
254184

255185

256186
if __name__ == "__main__":
257-
RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config', 'recreate_readme')
187+
RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config')
258188

259189
parser = ArgumentParser()
260190
parser.add_argument('cmd', choices=RUNNABLE_SCRIPTS)

0 commit comments

Comments
 (0)