Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite299dae

Browse files
authored
[3.11] Add Last-Translators to TX pull commit message (#100)
Backport of#88 to 3.11 branch.
1 parent4439c0a commite299dae

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

‎manage_translation.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# * fetch: fetch translations from transifex.com and strip source lines from the
1111
# files.
1212
# * recreate_tx_config: recreate configuration for all resources.
13+
# * generate_commit_msg: generates commit message with co-authors
1314

1415
fromargparseimportArgumentParser
1516
importos
@@ -18,13 +19,13 @@
1819
fromdifflibimportSequenceMatcher
1920
fromitertoolsimportcombinations
2021
frompathlibimportPath
21-
fromsubprocessimportcall
22+
fromsubprocessimportcall,run,CalledProcessError
2223
importsys
2324
fromtempfileimportTemporaryDirectory
2425
fromtypingimportSelf,Generator,Iterable
2526
fromwarningsimportwarn
2627

27-
frompolibimportpofile
28+
frompolibimportpofile,POFile
2829
fromtransifex.apiimporttransifex_api
2930

3031
LANGUAGE='pl'
@@ -190,8 +191,62 @@ def language_switcher(entry: ResourceLanguageStatistics) -> bool:
190191
returnany(entry.name.startswith(prefix)forprefixinlanguage_switcher_resources_prefixes)
191192

192193

194+
defgenerate_commit_msg():
195+
"""Generate a commit message
196+
Parses staged files and generates a commit message with Last-Translator's as
197+
co-authors.
198+
"""
199+
translators:set[str]=set()
200+
201+
result=run(
202+
['git','diff','--cached','--name-only','--diff-filter=ACM'],
203+
capture_output=True,
204+
text=True,
205+
check=True,
206+
)
207+
staged= [
208+
filenameforfilenameinresult.stdout.splitlines()iffilename.endswith('.po')
209+
]
210+
211+
forfileinstaged:
212+
staged_file=run(
213+
['git','show',f':{file}'],capture_output=True,text=True,check=True
214+
).stdout
215+
try:
216+
old_file=run(
217+
['git','show',f'HEAD:{file}'],
218+
capture_output=True,
219+
text=True,
220+
check=True,
221+
).stdout
222+
exceptCalledProcessError:
223+
old_file=''
224+
225+
new_po=pofile(staged_file)
226+
old_po=pofile(old_file)ifold_fileelsePOFile()
227+
old_entries= {entry.msgid:entry.msgstrforentryinold_po}
228+
229+
forentryinnew_po:
230+
ifentry.msgstrand (
231+
entry.msgidnotinold_entries
232+
orold_entries[entry.msgid]!=entry.msgstr
233+
):
234+
translator=new_po.metadata.get('Last-Translator')
235+
translator=translator.split(',')[0].strip()
236+
iftranslator:
237+
translators.add(f'Co-Authored-By:{translator}')
238+
break
239+
240+
print('Update translation from Transifex\n\n'+'\n'.join(translators))
241+
242+
193243
if__name__=="__main__":
194-
RUNNABLE_SCRIPTS= ('fetch','recreate_tx_config','warn_about_files_to_delete')
244+
RUNNABLE_SCRIPTS= (
245+
'fetch',
246+
'recreate_tx_config',
247+
'warn_about_files_to_delete',
248+
'generate_commit_msg',
249+
)
195250

196251
parser=ArgumentParser()
197252
parser.add_argument('cmd',choices=RUNNABLE_SCRIPTS)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp