diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/About.svelte | 2 | ||||
| -rw-r--r-- | src/locales/en.json | 16 | ||||
| -rw-r--r-- | src/locales/guided_translation.py | 91 |
3 files changed, 100 insertions, 9 deletions
diff --git a/src/components/About.svelte b/src/components/About.svelte index 817d9026..db74fd96 100644 --- a/src/components/About.svelte +++ b/src/components/About.svelte @@ -57,7 +57,7 @@ <ul class="w-full mx-auto md:w-[700px] lg:w-[500px] xl:w-auto text-secondary px-1 md:px-10 text-xl list-disc space-y-5" > - {#each $json('about.founder.qualifications') as qualification} + {#each Object.values($json('about.founder.qualifications')) as qualification} <li>{qualification}</li> {/each} </ul> diff --git a/src/locales/en.json b/src/locales/en.json index e4fb9f39..1d3446c9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -14,14 +14,14 @@ "header": "The Founder", "name": "Adam Soltys", "position": "Chief Technical Officer", - "qualifications": [ - "Running bitcoin since 2011", - "20+ years web development experience in government and industry", - "Early bitcoin Vancouver meetup organizer", - "Founder of The bitcoin Co-op and early supporter of Decentral Vancouver", - "Yogi, permaculturist, anarchist, decentralist", - "Husband, father, brother, son" - ] + "qualifications": { + "bitcoin": "Running bitcoin since 2011", + "webDev": "20+ years web development experience in government and industry", + "bitcoinVancouver": "Early bitcoin Vancouver meetup organizer", + "bitcoinCoop": "Founder of The bitcoin Co-op and early supporter of Decentral Vancouver", + "beliefs": "Yogi, permaculturist, anarchist, decentralist", + "familialRelationships": "Husband, father, brother, son" + } }, "locations": { "header": "Locations", diff --git a/src/locales/guided_translation.py b/src/locales/guided_translation.py new file mode 100644 index 00000000..e5f94cfe --- /dev/null +++ b/src/locales/guided_translation.py @@ -0,0 +1,91 @@ +#!/usr/bin/python + +import argparse, json, logging + +DEFAULT_FROM_LOCALE = 'en' + +def nested_dict_keys(d, _keyname_prefix=''): + entry_list = [] + for key in d: + value = d[key] + if isinstance(value, dict): + entry_list += nested_dict_keys(value, _keyname_prefix + key + '.') + else: + entry_list += [_keyname_prefix + key] + return entry_list + +def localize_string(string_id, from_data, to_data): + logging.debug("Translating string with id %s", string_id) + id_parts = string_id.split('.') + + # get original string + to_translate = from_data + for id_part in id_parts: + to_translate = to_translate[id_part] + + # get translated string + print("Please translate the following text (id " + string_id + "):") + print(to_translate) + + translated = input("Type the translated text then press ENTER: ") + + # find/create place to put translated string + translation_location = to_data # the dictionary or list that should contain the translated string + for id_part in id_parts[:-1]: + if id_part not in translation_location: + translation_location[id_part] = {} + translation_location = translation_location[id_part] + + translation_location[id_parts[-1]] = translated + +if __name__ == "__main__": + # setup and parse commandline arguments + args_parser = argparse.ArgumentParser(description="guided translation of CoinOS") + args_parser.add_argument('from_locale', nargs='?', type=str, + help='which locale to translate from') + args_parser.add_argument('to_locale', nargs='?', type=str, + help='which locale to translate to') + args = args_parser.parse_args() + + from_locale = args.from_locale or input("Which locale do you want to translate from (default: %s)? " + % DEFAULT_FROM_LOCALE) or DEFAULT_FROM_LOCALE + to_locale = args.to_locale or input("Which locale do you want to translate to? ") + if not to_locale: + raise ValueError("You need to specify a language to translate to.") + + logging.basicConfig(format='%(levelname)s: %(message)s') + + # load locale files + logging.debug("Reading file to convert from (%s.json)", from_locale) + with open(from_locale + ".json", 'r') as from_file: + from_json_text = from_file.read() + logging.debug("Converting from data from JSON to object") + from_data = json.loads(from_json_text) + from_id_list = nested_dict_keys(from_data) + logging.info("Successfully obtained %d strings from locale %s", + len(from_id_list), from_locale) + logging.debug("List of strings: %s", from_id_list) + + logging.debug("Reading file to convert to (%s.json)", to_locale) + with open(to_locale + ".json", 'r') as to_file: + to_json_text = to_file.read() + logging.debug("Converting to data from JSON to object") + to_data = json.loads(to_json_text) + to_id_list = nested_dict_keys(to_data) + logging.info("Successfully obtained %d strings from locale %s", + len(to_id_list), to_locale) + logging.debug("List of strings: %s", to_id_list) + + # localize strings! + try: + for string_id in from_id_list: + if string_id not in to_id_list: + localize_string(string_id, from_data, to_data) + to_id_list.append(string_id) + except KeyboardInterrupt: + print("Program interrupted. Saving strings and closing program...") + + # save localized data + with open(to_locale + ".json", 'w') as to_file: + json.dump(to_data, to_file, ensure_ascii=False, indent=2) + logging.info("Saved %d localized strings to %s.json", len(to_id_list), to_locale) |
