diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
commit | 75417f5e3d32645859d94cec82255dc130ec4a2e (patch) | |
tree | 5fd46925c6b4a881c9208772ed8e5cc0588bc164 /scripts/fix_placeholders.py | |
parent | Initial commit. (diff) | |
download | privacybadger-upstream.tar.xz privacybadger-upstream.zip |
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/fix_placeholders.py')
-rwxr-xr-x | scripts/fix_placeholders.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/fix_placeholders.py b/scripts/fix_placeholders.py new file mode 100755 index 0000000..e940dcc --- /dev/null +++ b/scripts/fix_placeholders.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import json + +from collections import OrderedDict +from glob import glob + +SOURCE_LOCALE = 'src/_locales/en_US/messages.json' + + +def fix_locale(locale, placeholder_keys): + # read in locale, preserving existing ordering + with open(locale, 'r') as f: + data = json.load(f, object_pairs_hook=OrderedDict) + + # restore missing placeholders + for key in placeholder_keys: + if key in data and "placeholders" not in data[key]: + data[key]["placeholders"] = source_data[key]["placeholders"] + + with open(locale, 'w') as f: + json.dump(data, f, ensure_ascii=False, indent=4) + + +if __name__ == '__main__': + with open(SOURCE_LOCALE, 'r') as f: + source_data = json.load(f, object_pairs_hook=OrderedDict) + + # get keys of locale messages with placeholders + placeholder_keys = [] + for key in source_data: + if "placeholders" in source_data[key]: + placeholder_keys.append(key) + + # fix all locales + for locale in glob('src/_locales/*/*.json'): + if locale == SOURCE_LOCALE: + continue + + fix_locale(locale, placeholder_keys) |