Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/update-lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
python-version: 3
- run: sudo apt-get install -y gettext
- run: pip install requests cogapp
- run: pip install requests cogapp polib
- uses: actions/checkout@master
with:
ref: ${{ matrix.version }}
Expand All @@ -31,7 +31,7 @@ jobs:
- run: ./manage_translation.py fetch
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- run: cog -rP README.md
- run: python -Werror -m cogapp -rP README.md
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- run: git config --local user.email github-actions@github.com
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ f'''![build](https://github.com/python/python-docs-pl/workflows/.github/workflow
![build](https://github.com/python/python-docs-pl/workflows/.github/workflows/update-and-build.yml/badge.svg)
![48.63% przełącznika języków](https://img.shields.io/badge/przełącznik_języków-48.63%25-0.svg)
![postęp tłumaczenia całości dokumentacji](https://img.shields.io/badge/całość-3.52%25-0.svg)
![19 tłumaczy](https://img.shields.io/badge/tłumaczy-19-0.svg)
![18 tłumaczy](https://img.shields.io/badge/tłumaczy-18-0.svg)
<!-- [[[end]]] -->

Jeśli znalazłeś(-aś) błąd lub masz sugestię,
Expand Down
45 changes: 35 additions & 10 deletions manage_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
# * regenerate_tx_config: recreate configuration for all resources.

from argparse import ArgumentParser
from collections import Counter
import os
from dataclasses import dataclass
from difflib import SequenceMatcher
from itertools import combinations
from pathlib import Path
from re import match
from subprocess import call, run
from subprocess import call
import sys
from typing import Self, Callable
from urllib.parse import urlparse, parse_qs
from warnings import warn

from polib import pofile

LANGUAGE = 'pl'

Expand Down Expand Up @@ -168,14 +173,34 @@ def progress_from_resources(resources: list[ResourceLanguageStatistics], filter_


def get_number_of_translators():
process = run(
['grep', '-ohP', r'(?<=^# )(.+)(?=, \d+$)', '-r', '.'],
capture_output=True,
text=True,
)
translators = [match('(.*)( <.*>)?', t).group(1) for t in process.stdout.splitlines()]
unique_translators = Counter(translators).keys()
return len(unique_translators)
translators = _fetch_translators()
_remove_aliases(translators)
_check_for_new_aliases(translators)
return len(translators)


def _fetch_translators() -> set[str]:
translators = set()
for file in Path().rglob('*.po'):
header = pofile(file).header.splitlines()
for translator_record in header[header.index('Translators:') + 1:]:
translator, _year = translator_record.split(', ')
translators.add(translator)
return translators


def _remove_aliases(translators: set[str]) -> None:
for alias, main in (("m_aciek <maciej.olko@gmail.com>", "Maciej Olko <maciej.olko@gmail.com>"),):
translators.remove(alias)
assert main in translators


def _check_for_new_aliases(translators) -> None:
for pair in combinations(translators, 2):
if (ratio := SequenceMatcher(lambda x: x in '<>@', *pair).ratio()) > 0.64:
warn(
f"{pair} are similar ({ratio:.3f}). Please add them to aliases list or bump the limit."
)


def language_switcher(entry: ResourceLanguageStatistics) -> bool:
Expand Down