diff --git a/fill_locale_placeholders.py b/fill_locale_placeholders.py new file mode 100644 index 00000000..37027738 --- /dev/null +++ b/fill_locale_placeholders.py @@ -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) diff --git a/pull_locales.sh b/pull_locales.sh new file mode 100755 index 00000000..a1e4531d --- /dev/null +++ b/pull_locales.sh @@ -0,0 +1,2 @@ +ruby pull_locales.rb +python fill_locale_placeholders.py