Add placeholders after downloading locales from Transifex
This commit is contained in:
parent
7ae07b063b
commit
f8a3bd14ae
30
fill_locale_placeholders.py
Normal file
30
fill_locale_placeholders.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
#! python2
|
||||
import io, os, json, re
|
||||
from collections import OrderedDict
|
||||
|
||||
with io.open('_locales/en/messages.json', 'r', encoding='utf-8') as f:
|
||||
english_placeholders = [(k, v['placeholders']) for k,v in json.load(f).items()
|
||||
if 'placeholders' in v]
|
||||
|
||||
for locale_name in os.listdir('_locales'):
|
||||
if locale_name == 'en':
|
||||
continue
|
||||
loc_path = '_locales/' + locale_name + '/messages.json'
|
||||
with io.open(loc_path, 'r+', encoding='utf-8') as f:
|
||||
loc = json.load(f, object_pairs_hook=OrderedDict)
|
||||
|
||||
changed = 0
|
||||
for msgId, placeholder in english_placeholders:
|
||||
if msgId in loc and cmp(placeholder, loc[msgId].get('placeholders', None))!=0:
|
||||
loc[msgId]['placeholders'] = placeholder
|
||||
changed += 1
|
||||
|
||||
if changed > 0:
|
||||
f.seek(0)
|
||||
json_str = json.dumps(loc, indent=1, ensure_ascii=False,
|
||||
separators=(',', ': '), encoding='utf-8')
|
||||
json_tabs = re.sub(r'^\s+', lambda s: s.group(0).replace(' ', '\t'),
|
||||
json_str, flags=re.MULTILINE)
|
||||
f.write(json_tabs)
|
||||
f.truncate()
|
||||
print 'Placeholders added to %s: %d' % (locale_name, changed)
|
2
pull_locales.sh
Executable file
2
pull_locales.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
ruby pull_locales.rb
|
||||
python fill_locale_placeholders.py
|
Loading…
Reference in New Issue
Block a user