1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/python3
# SPDX-License-Identifier: LGPL-2.1+
import sys
import os
import subprocess
def _do_msgattrib(fn):
argv = [
'msgattrib',
'--no-location',
'--translated',
'--no-wrap',
'--sort-output',
fn,
'--output-file=' + fn,
]
ret = subprocess.run(argv)
if ret.returncode != 0:
return
def _do_nukeheader(fn):
clean_lines = []
with open(fn) as f:
lines = f.readlines()
for line in lines:
if line.startswith('"POT-Creation-Date:'):
continue
if line.startswith('"PO-Revision-Date:'):
continue
if line.startswith('"Last-Translator:'):
continue
clean_lines.append(line)
with open(fn, 'w') as f:
f.writelines(clean_lines)
def _process_file(fn):
_do_msgattrib(fn)
_do_nukeheader(fn)
if __name__ == '__main__':
if len(sys.argv) == 1:
print('path required')
sys.exit(1)
try:
dirname = sys.argv[1]
for fn in os.listdir(dirname):
if fn.endswith('.po'):
_process_file(os.path.join(dirname, fn))
except NotADirectoryError as _:
print('path required')
sys.exit(2)
|