diff --git a/.github/workflows/update-lint-and-build.yml b/.github/workflows/update-lint-and-build.yml index 0f19848520..210855fc5c 100644 --- a/.github/workflows/update-lint-and-build.yml +++ b/.github/workflows/update-lint-and-build.yml @@ -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 }} @@ -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 diff --git a/README.md b/README.md index a0c2000ff0..5716458056 100644 --- a/README.md +++ b/README.md @@ -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) Jeśli znalazłeś(-aś) błąd lub masz sugestię, diff --git a/manage_translation.py b/manage_translation.py index 11ad8a2a27..b512606e27 100755 --- a/manage_translation.py +++ b/manage_translation.py @@ -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' @@ -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 "),): + 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: