Skip to content

Instantly share code, notes, and snippets.

@erral
Last active June 21, 2021 07:09
Show Gist options
  • Save erral/e1c12a550435703b267cd0db85219a44 to your computer and use it in GitHub Desktop.
Save erral/e1c12a550435703b267cd0db85219a44 to your computer and use it in GitHub Desktop.
Update jitsi-meet translation files with the new messages
# -*- coding: utf-8 -*-
"""
This script takes the main.json file, compares it with the json file provided
as a parameter and adds the missing keys to the provided file.
This way the language files can be updated without losing the existing translations.
The result of the script is a new file, this way the original file is left untouch.
"""
import json
import sys
def merge_json_tree(original, translation):
new_json = {}
if isinstance(original, dict):
for key, values in original.items():
if key not in translation:
# First scenario: keys are not available in the translation
# copy-over
new_json[key] = values
else:
new_json[key] = merge_json_tree(values, translation[key])
return new_json
else:
return translation
def main(translation_filename):
with open(translation_filename) as fp:
translation_json = json.load(fp)
with open("main.json") as original_fp:
main_json = json.load(original_fp)
new_translation_json = merge_json_tree(main_json, translation_json)
with open("updated-{}".format(translation_filename), "w") as new_fp:
json.dump(new_translation_json, new_fp)
if __name__ == "__main__":
translation_filename = sys.argv[1]
main(translation_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment