From b426a9fe5c0ea501a4b674cf97de4c164f07070a Mon Sep 17 00:00:00 2001 From: flb Date: Sun, 17 Oct 2021 13:05:01 +0200 Subject: [PATCH] add localizer script (https://github.com/HamletDuFromage/aio-switch-updater/issues/148) --- README.md | 4 + localizer.py | 78 ++++++++++++++ resources/i18n/en-US/menus.json | 2 +- resources/i18n/fr/menus.json | 13 +-- scripts/sed_replace.sh | 1 - scripts/translator.py | 176 -------------------------------- 6 files changed, 90 insertions(+), 184 deletions(-) create mode 100755 localizer.py delete mode 100644 scripts/sed_replace.sh delete mode 100644 scripts/translator.py diff --git a/README.md b/README.md index 9f39fcd..5f868c7 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ $ make +## Contribute + +PRs and suggestions are encouraged! If you wish to help with the localization of the app, you can translate the files in `resources/i18n/`. To easily find the non-translated strings and translate them, you may use `localizer.py` (e.g. `python localizer.py -r resources//i18n//en-US//menus.json -w resources//i18n//fr//menus.json`). + ## Disclaimer I do not own, host nor distribute any of the files that can be downloaded with this homebrew tool. At the owner's request, I will immediately remove the ability to download any problematic file. diff --git a/localizer.py b/localizer.py new file mode 100755 index 0000000..8abbb8a --- /dev/null +++ b/localizer.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +import json +import argparse + + +class Colors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + + def color_string(self, message): + return f"{self.OKCYAN}{message}{self.ENDC}" + + +class Localizer: + def __init__(self, reference_path, working_path): + self.reference_dict = dict() + self.working_dict = dict() + self.out_dict = dict() + self.reference_path = reference_path + self.working_path = working_path + self.init_dicts() + + def init_dicts(self): + with open(self.reference_path) as reference_file: + self.reference_dict = json.load(reference_file) + with open(self.working_path) as working_file: + self.working_dict = json.load(working_file) + + def get_new_dict(self): + self.out_dict = self.update_values(self.reference_dict, self.working_dict)[0] + + def update_values(self, reference_dict, working_dict): + colors = Colors() + done = False + for key, value in reference_dict.items(): + if done: + return (working_dict, True) + if isinstance(value, dict): + if key not in working_dict: + working_dict[key] = dict() + working_dict[key], done = self.update_values( + value, working_dict[key]) + elif key not in working_dict: + working_val = input( + f"Translation for key: [{key}] was not found.\nType in the translation in the field below.\nType \"_exit\" to save & quit and \"_skip\" to go to skip to the next key.\n<<< {colors.color_string(repr(value)[1:-1])}\n>>> ") + if working_val == "_exit": + return (working_dict, True) + elif working_val == "_skip": + continue + working_dict[key] = working_val + return (working_dict, False) + + def update_file(self): + self.get_new_dict() + with open(self.working_path, 'w') as working_file: + json.dump(self.out_dict, working_file, indent=2, ensure_ascii=False) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="Compare and update JSON translation files") + required = parser.add_argument_group('Required arguments') + required.add_argument('-r', '--reference', + help='reference file', required=True) + required.add_argument( + '-w', '--working', help='working file, will be edited', required=True) + args = parser.parse_args() + + loc = Localizer(args.reference, args.working) + loc.update_file() diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index 052cf0e..0235eda 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -15,7 +15,7 @@ "view": "View installed cheats", "exclude": "Exclude games from receiving cheat updates", "delete_existing": "Delete all existing cheat codes", - "delete_orphaned": "Delete orphaned cheat chodes", + "delete_orphaned": "Delete orphaned cheat codes", "deleting": "Deleting…", "cheastlips_title": "Cheatslips cheats", "gbatemp_title": "GBAtemp cheats", diff --git a/resources/i18n/fr/menus.json b/resources/i18n/fr/menus.json index 6c228d0..385187f 100644 --- a/resources/i18n/fr/menus.json +++ b/resources/i18n/fr/menus.json @@ -2,7 +2,7 @@ "about": { "title": "All-in-One Nintendo Switch Updater", "copyright": "AIO-switch-updater est distribuée sous la license GPL-3.0\n© 2020-2021 HamletDuFromage", - "disclaimers": "\ue016 À part les cheat codes qui proviennent d'un mirroir d'un topic Gbatemp, HamletDuFromage n'héberge rien. Tous les crédits vont aux propriétaires respectifs.\n\ue016 Les liens sont actualisés toutes les 3 heures. Si un lien reste inactif après 3 heures, merci de bien vouloir ouvrir une issue sur GitHub.\n" + "disclaimers": " À part les cheat codes qui proviennent d'un mirroir d'un topic Gbatemp, HamletDuFromage n'héberge rien. Tous les crédits vont aux propriétaires respectifs.\n Les liens sont actualisés toutes les 3 heures. Si un lien reste inactif après 3 heures, merci de bien vouloir ouvrir une issue sur GitHub.\n" }, "cheats": { "installed": "Codes de triche installés", @@ -18,7 +18,8 @@ "deleting": "Suppression en cours", "exclude_titles": "Exclure des titres", "exclude_titles_desc": "Vous pouvez desactiver les mises à jour de codes dans ce menu", - "exclude_titles_save": "Sauvegarde et retour" + "exclude_titles_save": "Sauvegarde et retour", + "delete_orphaned": "Supprimer les codes de triche orphelins" }, "common": { "downloading": "Téléchargement en cours…", @@ -61,16 +62,16 @@ }, "main": { "getting": "Téléchargement de {}", - "firmware_text": "\ue016 Firmware depuis 'https://darthsternie.net/switch-firmwares/'. Une fois téléchargés, ils seront dans '/firmware'. Vous pouvez ensuite les installer avec Daybreak.\n\ue016 FW actuel : ", - "cheats_text": "\ue016 Archive mise à jour quotidiennement des codes de triche de 'gbatemp.net'. Les codes de triche pour les jeux que vous ne possedez pas ne seront pas extraits sur votre carte SD. Vous pouvez désactiver les mises à jour pour pour une sélection de jeux dans le menu 'Outils->Menu de cheat'.\n\ue016 Version actuelle des cheats : ", + "firmware_text": " Firmware depuis 'https://darthsternie.net/switch-firmwares/'. Une fois téléchargés, ils seront dans '/firmware'. Vous pouvez ensuite les installer avec Daybreak.\n FW actuel : ", + "cheats_text": " Archive mise à jour quotidiennement des codes de triche de 'gbatemp.net'. Les codes de triche pour les jeux que vous ne possedez pas ne seront pas extraits sur votre carte SD. Vous pouvez désactiver les mises à jour pour pour une sélection de jeux dans le menu 'Outils->Menu de cheat'.\n Version actuelle des cheats : ", "sigpatches": "sigpatches", - "sigpatches_text": "\ue016 Les Sigpatches permettent à votre Switch d'installer et d'exécuter des fichiers NSP non officiels. Assurez-vous de choisir les bons patchs pour votre configuration (Atmosphère seul ou Hekate + Atmosphère).", + "sigpatches_text": " Les Sigpatches permettent à votre Switch d'installer et d'exécuter des fichiers NSP non officiels. Assurez-vous de choisir les bons patchs pour votre configuration (Atmosphère seul ou Hekate + Atmosphère).", "firmware": "firmware", "not_found": "non trouvé", "latest_cheats": "Dernière version", "app": "app", "cfw": "CFW", - "cfw_text": "\ue016 Principaux CFWs. Si vous souhaitez utiliser Atmosphère avec Hekate, téléchargez Atmosphère, puis Hekate.", + "cfw_text": " Principaux CFWs. Si vous souhaitez utiliser Atmosphère avec Hekate, téléchargez Atmosphère, puis Hekate.", "cheats": "codes de triche", "links_not_found": "Impossible de trouver un lien de téléchargement, assurez-vous que la Switch soit connectée à internet.\nSi ce problème persiste, veuillez ouvrir une issue sur GitHub.", "new_update": " - Nouvelle MÀJ de l'app disponible", diff --git a/scripts/sed_replace.sh b/scripts/sed_replace.sh deleted file mode 100644 index cc9a021..0000000 --- a/scripts/sed_replace.sh +++ /dev/null @@ -1 +0,0 @@ -find . -type f -exec sed -i 's#menus/About_Title#menus/about/title#g;s#menus/copyright#menus/about/copyright#g;s#menus/Disclaimers#menus/about/disclaimers#g;s#menus/donate#menus/about/donate#g;s#menus/app_title#menus/cheats/installed#g;s#menus/app_label#menus/cheats/label#g;s#menus/text_download#menus/cheats/downloading#g;s#menus/text_download_list#menus/cheats/dl_latest#g;s#menus/text_title#menus/cheats/getting_cheats#g;s#menus/Downloading#menus/common/downloading#g;s#menus/tool_extracting#menus/common/extracting#g;s#menus/Extracting#menus/common/extracting#g;s#menus/All_done#menus/common/all_done#g;s#menus/Changelog#menus/changelog/changelog#g;s#menus/cheat_menu#menus/cheats/menu#g;s#menus/cheat_view#menus/cheats/view#g;s#menus/cheat_exclude#menus/cheats/exclude#g;s#menus/cheat_delete_all_ex#menus/cheats/delete_existing#g;s#menus/cheat_delete_all_cheat#menus/cheats/delete_all#g;s#menus/cheat_Deleting#menus/cheats/deleting#g;s#menus/cheat_All_done#menus/common/all_done#g;s#menus/please_reboot#menus/sigpatches/reboot#g;s#menus/cheastlips_title#menus/cheats/cheastlips_title#g;s#menus/get_cheatslips#menus/cheats/get_cheatslips#g;s#menus/cheatslips_label#menus/cheats/cheatslips_label#g;s#menus/download_cheatslips#menus/cheats/cheatslips_dl#g;s#menus/delete_cheat#menus/cheats/delete_file#g;s#menus/couldnt_dl_cheats#menus/cheats/cheatslips_error#g;s#menus/quota_cheatslips#menus/cheats/quota#g;s#menus/cheat_cheat_content#menus/cheats/sheet_content#g;s#menus/app_cheatslips_label#menus/cheats/cheatslips_select#g;s#menus/wrong_cheatslips_id#menus/cheats/cheatslips_wrong_id#g;s#menus/keyboard_no_show#menus/cheats/kb_error#g;s#menus/see_more#menus/cheats/cheatslips_see_more#g;s#menus/download_cheats#menus/cheats/cheatslips_dl_cheats#g;s#menus/bid_not_found#menus/cheats/bid_not_found#g;s#menus/choice_yes#menus/common/Yes#g;s#menus/choice_no#menus/common/No#g;s#menus/Back#menus/common/back#g;s#menus/Continue#menus/common/continue#g;s#menus/Download_payloads#menus/payloads/dl_payloads#g;s#menus/select#menus/payloads/select#g;s#menus/Download#menus/common/download#g;s#menus/from#menus/common/from#g;s#menus/down#menus/common/downloading#g;s#menus/download_all_done#menus/common/all_done#g;s#menus/description#menus/payloads/not_found#g;s#menus/back#menus/common/back#g;s#menus/exclude_titles#menus/cheats/exclude_titles#g;s#menus/you_can#menus/cheats/exclude_titles_desc#g;s#menus/save#menus/cheats/exclude_titles_save#g;s#menus/joy_con#menus/joy_con/title#g;s#menus/jc_you_can_1#menus/joy_con/desc_1#g;s#menus/jc_you_can_goto#menus/joy_con/desc_2#g;s#menus/jc_you_can_2#menus/joy_con/desc_3#g;s#menus/jc_backup#menus/joy_con/backup#g;s#menus/jc_color#menus/joy_con/label#g;s#menus/jc_backing#menus/joy_con/backing_up#g;s#menus/jc_all_done#menus/common/all_done#g;s#menus/jc_change#menus/joy_con/changing#g;s#menus/jc_all_#menus/joy_con/all_done#g;s#menus/pro_con#menus/pro_con/title#g;s#menus/pc_you_can#menus/pro_con/desc#g;s#menus/pc_color#menus/pro_con/label#g;s#menus/pc_backing#menus/pro_con/backing_up#g;s#menus/pc_all_done#menus/pro_con/all_done#g;s#menus/Getting#menus/main/getting#g;s#menus/firmware_text#menus/main/firmware_text#g;s#menus/currentCeatsver#menus/main/cheats_text#g;s#menus/operation_1#menus/main/sigpatches#g;s#menus/list_sigpatches#menus/main/sigpatches_text#g;s#menus/operation_2#menus/main/firmware#g;s#menus/list_not#menus/main/not_found#g;s#menus/list_latest#menus/main/latest_cheats#g;s#menus/list_app#menus/main/app#g;s#menus/list_cfw#menus/main/cfw#g;s#menus/list_ams#menus/main/ams_text#g;s#menus/list_main#menus/main/cfw_text#g;s#menus/list_latest_ver#menus/main/cheats_text#g;s#menus/list_cheats#menus/main/cheats#g;s#menus/list_down#menus/common/download#g;s#menus/list_from#menus/common/from#g;s#menus/list_downing#menus/common/downloading#g;s#menus/list_extracting#menus/common/extracting#g;s#menus/list_All#menus/common/all_done#g;s#menus/list_could_done#menus/main/links_not_found#g;s#menus/main_app#menus/main/new_update#g;s#menus/main_about#menus/main/about#g;s#menus/main_update_ams#menus/main/update_ams#g;s#menus/main_update_cfw#menus/main/update_cfw#g;s#menus/main_update_si#menus/main/update_sigpatches#g;s#menus/main_firmwares#menus/main/download_firmware#g;s#menus/main_cheats#menus/main/download_cheats#g;s#menus/main_tools#menus/main/tools#g;s#menus/payload_reboot#menus/payloads/reboot_title#g;s#menus/payload_select#menus/payloads/select#g;s#menus/payload_set#menus/payloads/set_reboot_payload#g;s#menus/payload_set_up#menus/payloads/set_update_bin#g;s#menus/payload_success#menus/payloads/copy_success#g;s#menus/payload_to#menus/payloads/to#g;s#menus/payload_ok#menus/common/ok#g;s#menus/payload_shut#menus/common/shut_down#g;s#menus/payload_reboot_2#menus/common/reboot#g;s#menus/hide_tabs_page#menus/hide/title#g;s#menus/hide_tabs_label#menus/hide/desc#g;s#menus/tool_cheats#menus/tools/cheats#g;s#menus/tool_change#menus/tools/joy_cons#g;s#menus/tool_change_procon#menus/tools/pro_cons#g;s#menus/tool_download#menus/tools/dl_payloads#g;s#menus/tool_inject#menus/tools/inject_payloads#g;s#menus/tool_update#menus/tools/update_app#g;s#menus/tool_DownLoad#menus/tools/dl_app#g;s#menus/tool_updating#menus/common/updating#g;s#menus/tool_downloading#menus/common/downloading#g;s#menus/tool_all_done#menus/common/all_done#g;s#menus/tool_changelog#menus/tools/changelog#g;s#menus/tool_cleanUp#menus/tools/clean_up#g;s#menus/hide_tabs#menus/tools/hide_tabs#g;s#menus/tool_net_settings#menus/tools/internet_settings#g;s#menus/tool_browser#menus/tools/browser#g;s#menus/utils_because#menus/utils/fw_warning#g;s#menus/utils_ok#menus/common/ok#g;s#menus/utils_do#menus/utils/overwrite#g;s#menus/utils_no#menus/common/no#g;s#menus/utils_yes#menus/common/yes#g;s#menus/utils_the#menus/utils/wrong_type_sigpatches#g;s#menus/utils_the_downloaded#menus/utils/wrong_type_fw#g;s#menus/ultils_overwrite#menus/utils/overwrite_inis#g;s#menus/ultis_file#menus/utils/wrong_type_cfw#g;s#menus/reboot_rcm#menus/ams_update/reboot_rcm#g;s#menus/hekate_dialogue#menus/ams_update/install_hekate#g;s#menus/Yes#menus/common/yes#g;s#menus/No#menus/common/no#g;s#menus/net_settings#menus/net/title#g;s#menus/go_back#menus/common/go_back#g;s#menus/Confirm_button#menus/common/confirm#g;s#menus/Cancel_button#menus/common/cancel#g;s#menus/tool_copyFiles#menus/tools/batch_copy#g;s#menus/files_not_found#menus/tools/batch_copy_not_found#g;s#menus/copy_files_not_found#menus/tools/batch_copy_config_not_found#g;s#menus/delete_contents#menus/ams_update/delete_contents#g;s#menus/launch_warning#menus/main/launch_warning#g' {} \; \ No newline at end of file diff --git a/scripts/translator.py b/scripts/translator.py deleted file mode 100644 index 4eb1976..0000000 --- a/scripts/translator.py +++ /dev/null @@ -1,176 +0,0 @@ -import json - -lookupTable = { - "About_Title" : ["about", "title"], - "copyright" : ["about", "copyright"], - "Disclaimers" : ["about", "disclaimers"], - "donate" : ["about", "donate"], - "app_title" : ["cheats", "installed"], - "app_label" : ["cheats", "label"], - "text_download" : ["cheats", "downloading"], - "text_download_list" : ["cheats", "dl_latest"], - "text_title": ["cheats", "getting_cheats"], - "Downloading" : ["common", "downloading"], - "tool_extracting" : ["common", "extracting"], - "Extracting" : ["common", "extracting"], - "All_done" : ["common", "all_done"], - "Changelog" : ["changelog", "changelog"], - "cheat_menu" : ["cheats", "menu"], - "cheat_view" : ["cheats", "view"], - "cheat_exclude" : ["cheats", "exclude"], - "cheat_delete_all_ex" : ["cheats", "delete_existing"], - "cheat_delete_all_cheat" : ["cheats", "delete_all"], - "cheat_Deleting" : ["cheats", "deleting"], - "cheat_All_done" : ["common", "all_done"], - "please_reboot" : ["sigpatches", "reboot"], - "cheastlips_title" : ["cheats", "cheastlips_title"], - "get_cheatslips" : ["cheats", "get_cheatslips"], - "cheatslips_label" : ["cheats", "cheatslips_label"], - "download_cheatslips" : ["cheats", "cheatslips_dl"], - "delete_cheat" : ["cheats", "delete_file"], - "couldnt_dl_cheats" : ["cheats", "cheatslips_error"], - "quota_cheatslips" : ["cheats", "quota"], - "cheat_cheat_content" : ["cheats", "sheet_content"], - "app_cheatslips_label" : ["cheats", "cheatslips_select"], - "wrong_cheatslips_id" : ["cheats", "cheatslips_wrong_id"], - "keyboard_no_show" : ["cheats", "kb_error"], - "see_more" : ["cheats", "cheatslips_see_more"], - "download_cheats" : ["cheats", "cheatslips_dl_cheats"], - "bid_not_found" : ["cheats", "bid_not_found"], - "choice_yes": ["common", "Yes"], - "choice_no": ["common", "No"], - "Back" : ["common", "back"], - "Continue" : ["common", "continue"], - "Download_payloads" : ["payloads", "dl_payloads"], - "select" : ["payloads", "select"], - "Download" : ["common", "download"], - "from" : ["common", "from"], - "down" : ["common", "downloading"], - "download_all_done" : ["common", "all_done"], - "description" : ["payloads", "not_found"], - "back" : ["common", "back"], - "exclude_titles" : ["cheats", "exclude_titles"], - "you_can" : ["cheats", "exclude_titles_desc"], - "save" : ["cheats", "exclude_titles_save"], - "joy_con" : ["joy_con", "title"], - "jc_you_can_1" : ["joy_con", "desc_1"], - "jc_you_can_goto" : ["joy_con", "desc_2"], - "jc_you_can_2" : ["joy_con", "desc_3"], - "jc_backup" : ["joy_con", "backup"], - "jc_color" : ["joy_con", "label"], - "jc_backing" : ["joy_con", "backing_up"], - "jc_all_done" : ["common", "all_done"], - "jc_change" : ["joy_con", "changing"], - "jc_all_" : ["joy_con", "all_done"], - "pro_con" : ["pro_con", "title"], - "pc_you_can" : ["pro_con", "desc"], - "pc_color" : ["pro_con", "label"], - "pc_backing" : ["pro_con", "backing_up"], - "pc_all_done" : ["pro_con", "all_done"], - "Getting" : ["main", "getting"], - "firmware_text" : ["main", "firmware_text"], - "currentCeatsver" : ["main", "cheats_text"], - "operation_1" : ["main", "sigpatches"], - "list_sigpatches" : ["main", "sigpatches_text"], - "operation_2" : ["main", "firmware"], - "list_not" : ["main", "not_found"], - "list_latest" : ["main", "latest_cheats"], - "list_app" : ["main", "app"], - "list_cfw" : ["main", "cfw"], - "list_ams": ["main", "ams_text"], - "list_main" : ["main", "cfw_text"], - "list_latest_ver" : ["main", "cheats_text"], - "list_cheats" : ["main", "cheats"], - "list_down" : ["common", "download"], - "list_from" : ["common", "from"], - "list_downing" : ["common", "downloading"], - "list_extracting" : ["common", "extracting"], - "list_All" : ["common", "all_done"], - "list_could_done" : ["main", "links_not_found"], - "main_app" : ["main", "new_update"], - "main_about" : ["main", "about"], - "main_update_ams" : ["main", "update_ams"], - "main_update_cfw" : ["main", "update_cfw"], - "main_update_si" : ["main", "update_sigpatches"], - "main_firmwares" : ["main", "download_firmware"], - "main_cheats" : ["main", "download_cheats"], - "main_tools" : ["main", "tools"], - "payload_reboot" : ["payloads", "reboot_title"], - "payload_select" : ["payloads", "select"], - "payload_set" : ["payloads", "set_reboot_payload"], - "payload_set_up" : ["payloads", "set_update_bin"], - "payload_success" : ["payloads", "copy_success"], - "payload_to" : ["payloads", "to"], - "payload_ok" : ["common", "ok"], - "payload_shut" : ["common", "shut_down"], - "payload_reboot_2" : ["common", "reboot"], - "hide_tabs_page" : ["hide", "title"], - "hide_tabs_label" : ["hide", "desc"], - "tool_cheats" : ["tools", "cheats"], - "tool_change" : ["tools", "joy_cons"], - "tool_change_procon" : ["tools", "pro_cons"], - "tool_download" : ["tools", "dl_payloads"], - "tool_inject" : ["tools", "inject_payloads"], - "tool_update" : ["tools", "update_app"], - "tool_DownLoad" : ["tools", "dl_app"], - "tool_updating" : ["common", "updating"], - "tool_downloading" : ["common", "downloading"], - "tool_all_done" : ["common", "all_done"], - "tool_changelog" : ["tools", "changelog"], - "tool_cleanUp" : ["tools", "clean_up"], - "hide_tabs" : ["tools", "hide_tabs"], - "tool_net_settings" : ["tools", "internet_settings"], - "tool_browser" : ["tools", "browser"], - "utils_because" : ["utils", "fw_warning"], - "utils_ok" : ["common", "ok"], - "utils_do" : ["utils", "overwrite"], - "utils_no" : ["common", "no"], - "utils_yes" : ["common", "yes"], - "utils_the" : ["utils", "wrong_type_sigpatches"], - "utils_the_downloaded" : ["utils", "wrong_type_fw"], - "ultils_overwrite" : ["utils", "overwrite_inis"], - "ultis_file" : ["utils", "wrong_type_cfw"], - "reboot_rcm" : ["ams_update", "reboot_rcm"], - "hekate_dialogue" : ["ams_update", "install_hekate"], - "Yes" : ["common", "yes"], - "No" : ["common", "no"], - "net_settings" : ["net", "title"], - "go_back" : ["common", "go_back"], - "Confirm_button" : ["common", "confirm"], - "Cancel_button" : ["common", "cancel"], - "tool_copyFiles" : ["tools", "batch_copy"], - "files_not_found" : ["tools", "batch_copy_not_found"], - "copy_files_not_found" : ["tools", "batch_copy_config_not_found"], - "delete_contents" : ["ams_update", "delete_contents"], - "launch_warning" : ["main", "launch_warning"] -} - -lookupTableSmol = { - "About_Title" : ["about", "title"], - "copyright" : ["about", "copyright"], - "Disclaimers" : ["about", "disclaimer"] -} - -with open('menus.json') as json_file: - data = json.load(json_file) - -def populate(data, t): - res = {} - for e in t: - if(e in data): - if(t[e][0] not in res): - res[t[e][0]] = {} - res[t[e][0]][t[e][1]] = data[e] - return res - -def sed_command(t): - command = "'" - for e in t: - command += "s#" + "menus/" + e + "#" + "menus/" + t[e][0] + "/" + t[e][1] + "#g;" - command += command[:-1] + "'" - return command - -with open("menus.json", "w") as outfile: - json.dump(populate(data, lookupTable), outfile, ensure_ascii=False, indent=2) - -print(sed_command(lookupTable)) \ No newline at end of file