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

Commit0536ca7

Browse files
[3.13] Add Last-Translators to TX pull commit message (#98)
Co-authored-by: Stan Ulbrych <89152624+stanfromireland@users.noreply.github.com>
1 parent41efc04 commit0536ca7

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
@@ -11,6 +11,7 @@
1111
# files.
1212
# * recreate_tx_config: recreate configuration for all resources.
1313
# * warn_about_files_to_delete: lists files that are not available upstream
14+
# * generate_commit_msg: generates commit message with co-authors
1415

1516
fromargparseimportArgumentParser
1617
importos
@@ -19,13 +20,13 @@
1920
fromdifflibimportSequenceMatcher
2021
fromloggingimportinfo
2122
frompathlibimportPath
22-
fromsubprocessimportcall
23+
fromsubprocessimportcall,run,CalledProcessError
2324
importsys
2425
fromtempfileimportTemporaryDirectory
2526
fromtypingimportSelf,Generator,Iterable
2627
fromwarningsimportwarn
2728

28-
frompolibimportpofile
29+
frompolibimportpofile,POFile
2930
fromtransifex.apiimporttransifex_api
3031

3132
LANGUAGE='pl'
@@ -187,8 +188,62 @@ def language_switcher(entry: ResourceLanguageStatistics) -> bool:
187188
returnany(entry.name.startswith(prefix)forprefixinlanguage_switcher_resources_prefixes)
188189

189190

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

193248
parser=ArgumentParser()
194249
parser.add_argument('cmd',choices=RUNNABLE_SCRIPTS)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp