script to convert inline Summary to translatable file

https://forum.f-droid.org/t/translating-lots-of-app-summaries/
master
Hans-Christoph Steiner 2019-02-27 16:50:17 +01:00
parent 52160fedba
commit 4c1c4c28bf
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import glob
import os
import re
import yaml
os.chdir(os.path.dirname(__file__) + '/../')
for f in glob.glob('metadata/*.yml'):
with open(f) as fp:
raw = fp.read()
data = yaml.load(raw)
archive_policy = data.get('ArchivePolicy')
if 'Disabled' not in data and 'Summary' in data \
and (archive_policy is None or not archive_policy.startswith('0 ')):
en_US_dir = f[:-4] + '/en-US/'
os.makedirs(en_US_dir, exist_ok=True)
with open(en_US_dir + '/summary.txt', 'w') as fp:
fp.write(data['Summary'].strip().rstrip() + '\n')
with open(f, 'w') as out:
out.write(re.sub(r'Summary:[^\n]+\n', r'', raw))