diff --git a/.github/workflows/update-lint-and-build.yml b/.github/workflows/update-lint-and-build.yml index 47739abe05..117f89ec05 100644 --- a/.github/workflows/update-lint-and-build.yml +++ b/.github/workflows/update-lint-and-build.yml @@ -56,7 +56,7 @@ jobs: run: > ! git diff -I'^"POT-Creation-Date: ' -I'^"Language-Team: ' -I'^# ' -I'^"Last-Translator: ' -I'^"Project-Id-Version: ' --exit-code && echo "SIGNIFICANT_CHANGES=1" >> "$GITHUB_ENV" || exit 0 - run: git add . - - run: git commit -m 'Update translation from Transifex' + - run: git commit -m "$(python manage_translation.py generate_commit_msg)" if: env.SIGNIFICANT_CHANGES - name: Push commit uses: ad-m/github-push-action@master diff --git a/manage_translation.py b/manage_translation.py index e8a042a6a3..a41b4a91c3 100755 --- a/manage_translation.py +++ b/manage_translation.py @@ -11,6 +11,7 @@ # files. # * recreate_tx_config: recreate configuration for all resources. # * warn_about_files_to_delete: lists files that are not available upstream +# * generate_commit_msg: generates commit message with co-authors from argparse import ArgumentParser import os @@ -19,13 +20,13 @@ from difflib import SequenceMatcher from logging import info from pathlib import Path -from subprocess import call +from subprocess import call, run, CalledProcessError import sys from tempfile import TemporaryDirectory from typing import Self, Generator, Iterable from warnings import warn -from polib import pofile +from polib import pofile, POFile from transifex.api import transifex_api LANGUAGE = 'pl' @@ -149,12 +150,17 @@ def get_resource_language_stats() -> list[ResourceLanguageStatistics]: return [ResourceLanguageStatistics.from_api_entry(entry) for entry in resources] -def progress_from_resources(resources: Iterable[ResourceLanguageStatistics]) -> tuple[float, float]: +def progress_from_resources( + resources: Iterable[ResourceLanguageStatistics], +) -> tuple[float, float]: word_pairs = ((e.translated_words, e.total_words) for e in resources) string_pairs = ((e.translated_strings, e.total_strings) for e in resources) translated_total_words, total_words = (sum(counts) for counts in zip(*word_pairs)) translated_total_strs, total_strs = (sum(counts) for counts in zip(*string_pairs)) - return translated_total_words / total_words * 100, translated_total_strs / total_strs * 100 + return ( + translated_total_words / total_words * 100, + translated_total_strs / total_strs * 100, + ) def get_number_of_translators(): @@ -197,8 +203,62 @@ def language_switcher(entry: ResourceLanguageStatistics) -> bool: ) +def generate_commit_msg(): + """Generate a commit message + Parses staged files and generates a commit message with Last-Translator's as + co-authors. + """ + translators: set[str] = set() + + result = run( + ['git', 'diff', '--cached', '--name-only', '--diff-filter=ACM'], + capture_output=True, + text=True, + check=True, + ) + staged = [ + filename for filename in result.stdout.splitlines() if filename.endswith('.po') + ] + + for file in staged: + staged_file = run( + ['git', 'show', f':{file}'], capture_output=True, text=True, check=True + ).stdout + try: + old_file = run( + ['git', 'show', f'HEAD:{file}'], + capture_output=True, + text=True, + check=True, + ).stdout + except CalledProcessError: + old_file = '' + + new_po = pofile(staged_file) + old_po = pofile(old_file) if old_file else POFile() + old_entries = {entry.msgid: entry.msgstr for entry in old_po} + + for entry in new_po: + if entry.msgstr and ( + entry.msgid not in old_entries + or old_entries[entry.msgid] != entry.msgstr + ): + translator = new_po.metadata.get('Last-Translator') + translator = translator.split(',')[0].strip() + if translator: + translators.add(f'Co-Authored-By: {translator}') + break + + print('Update translation from Transifex\n\n' + '\n'.join(translators)) + + if __name__ == '__main__': - RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config', 'warn_about_files_to_delete') + RUNNABLE_SCRIPTS = ( + 'fetch', + 'recreate_tx_config', + 'warn_about_files_to_delete', + 'generate_commit_msg', + ) parser = ArgumentParser() parser.add_argument('cmd', choices=RUNNABLE_SCRIPTS) diff --git a/translation_progress_en.svg b/translation_progress_en.svg index 3d067a3358..79e28244d6 100644 --- a/translation_progress_en.svg +++ b/translation_progress_en.svg @@ -21,7647 +21,7647 @@ - - - - @@ -7669,186 +7669,186 @@ z - - @@ -7856,168 +7856,168 @@ z - - @@ -8025,204 +8025,204 @@ z - - @@ -8230,220 +8230,220 @@ z - - @@ -8451,212 +8451,212 @@ z - - @@ -8664,210 +8664,210 @@ z - - @@ -8877,42 +8877,42 @@ z - - @@ -8920,66 +8920,66 @@ z - - @@ -8987,60 +8987,60 @@ z - - @@ -9048,84 +9048,84 @@ z - - @@ -9133,11274 +9133,11274 @@ z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy