Created
February 3, 2025 21:28
-
-
Save Michae1Weiss/3f5e1010cd33f80c63ba41a23834d722 to your computer and use it in GitHub Desktop.
I was too lazy to translate all 80 files by myself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 02.02.2025 by Mykhailo Bilyi. | |
import os | |
import json | |
import glob | |
def process_arb_files(directory): | |
cupertino_files = glob.glob(os.path.join(directory, "cupertino_*.arb")) | |
updated_files = 0 | |
skipped_files = 0 | |
for cupertino_file in cupertino_files: | |
base_name = os.path.basename(cupertino_file).replace("cupertino_", "") | |
material_file = os.path.join(directory, f"material_{base_name}") | |
if not os.path.exists(material_file): | |
print(f"WARNING: No corresponding material file found for {cupertino_file}") | |
skipped_files += 1 | |
continue | |
with open(cupertino_file, "r", encoding="utf-8") as cf: | |
cupertino_data = json.load(cf) | |
if "cancelButtonLabel" not in cupertino_data or "backButtonLabel" not in cupertino_data: | |
print(f"WARNING: Missing required keys in {cupertino_file}") | |
skipped_files += 1 | |
continue | |
with open(material_file, "r", encoding="utf-8") as mf: | |
material_data = json.load(mf) | |
if "backButtonTooltip" in material_data and "cancelButtonLabel" in material_data: | |
cupertino_data["backButtonLabel"] = material_data["backButtonTooltip"] | |
cupertino_data["cancelButtonLabel"] = material_data["cancelButtonLabel"] | |
with open(cupertino_file, "w", encoding="utf-8") as cf: | |
json.dump(cupertino_data, cf, ensure_ascii=False, indent=2) | |
print(f"UPDATED: {cupertino_file} with values from {material_file}") | |
updated_files += 1 | |
else: | |
print(f"WARNING: Missing required keys in {material_file}") | |
skipped_files += 1 | |
print("\nSUMMARY:") | |
print(f"Total files updated: {updated_files}") | |
print(f"Total files skipped: {skipped_files}") | |
if __name__ == "__main__": | |
directory = "/home/mike/dev/flutter/forks/flutter/packages/flutter_localizations/lib/src/l10n" # TODO | |
process_arb_files(directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment