INNER CODE UNIT · Python
process_locale_files
futo-org/android-keyboard · tools/make-keyboard-text-py/src/migrate.py:45
def process_locale_files(base_dir):
for root, _, files in os.walk(base_dir):
for file in files:
if file.endswith('.xml'):
xml_file_path = os.path.join(root, file)
locale_code = root.split(os.sep)[-1].replace('values-', '')
if locale_code == "values":
locale_code = "DEFAULT"
if "-r" in locale_code:
locale_code = locale_code.replace("-r", "_")
json_data = {"locale": locale_code} | xml_to_dict(xml_file_path)
json_file_path = (f"locales/{locale_code}.json")
with open(json_file_path, 'w', encoding='utf-8') as json_file:
json.dump(json_data, json_file, ensure_ascii=False, indent=4)