[3.10] Add Last-Translators to TX pull commit message by m-aciek · Pull Request #101 · python/python-docs-pl · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

[3.10] Add Last-Translators to TX pull commit message #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.10
Choose a base branch
from
Open
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
61 changes: 59 additions & 2 deletions manage_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
# files.
# * recreate_readme: recreate readme to update translation progress.
# * regenerate_tx_config: recreate configuration for all resources.
# * generate_commit_msg: generates commit message with co-authors

from argparse import ArgumentParser
from collections import Counter
import os
from dataclasses import dataclass
from pathlib import Path
from re import match, search
from subprocess import call, run
from subprocess import call, run, CalledProcessError
import sys
from typing import Self
from urllib.parse import unquote
from warnings import warn

from polib import pofile, POFile

LANGUAGE = 'pl'


Expand Down Expand Up @@ -271,8 +274,62 @@ def average(averages, weights):
)


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', 'recreate_readme', 'warn_about_files_to_delete')
RUNNABLE_SCRIPTS = (
'fetch',
'recreate_tx_config',
'recreate_readme', 'warn_about_files_to_delete',
'generate_commit_msg',
)

parser = ArgumentParser()
parser.add_argument('cmd', choices=RUNNABLE_SCRIPTS)
Expand Down

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.