From 6fe5fe3b815afe21a541d3de2fbfc30e975596b0 Mon Sep 17 00:00:00 2001 From: Maciej Olko Date: Wed, 2 Jul 2025 23:21:30 +0200 Subject: [PATCH] [3.12] Add Last-Translators to TX pull commit message --- manage_translation.py | 61 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/manage_translation.py b/manage_translation.py index 8aaa104975..dc930ae922 100755 --- a/manage_translation.py +++ b/manage_translation.py @@ -10,6 +10,7 @@ # * fetch: fetch translations from transifex.com and strip source lines from the # files. # * recreate_tx_config: recreate configuration for all resources. +# * generate_commit_msg: generates commit message with co-authors from argparse import ArgumentParser import os @@ -18,13 +19,13 @@ from difflib import SequenceMatcher from itertools import combinations 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' @@ -182,8 +183,62 @@ def language_switcher(entry: ResourceLanguageStatistics) -> bool: return any(entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes) +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) 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