@@ -52,6 +52,7 @@ def main():
52
52
"ja" : "Japanese" ,
53
53
"ru" : "Russian"
54
54
}
55
+
55
56
# Read the input JSON file
56
57
with open ('../assets/flutter_i18n/en.json' , 'r' ) as file :
57
58
en_data = json .load (file )
@@ -68,15 +69,24 @@ def main():
68
69
# Find keys that are present in en.json but not in the current language file
69
70
new_entries = {key : en_data [key ] for key in en_data if key not in lang_data }
70
71
72
+ # Find keys that are present in the current language file but not in en.json
73
+ unused_keys = [key for key in lang_data if key not in en_data ]
74
+
75
+ # Remove unused keys from lang_data
76
+ for key in unused_keys :
77
+ del lang_data [key ]
78
+
71
79
# Translate the new entries
72
80
for key , value in new_entries .items ():
73
81
lang_data [key ] = translate (value , lang_name )
74
- time .sleep (10 ) # Pause for a bit between each translation r
82
+ time .sleep (10 ) # Pause for a bit between each translation request
83
+
84
+ # Write the updated language data back to the file
75
85
with open (f'../assets/flutter_i18n/{ lang_code } .json' , 'w' ) as file :
76
86
json .dump (lang_data , file , ensure_ascii = False , indent = 4 )
77
87
78
88
print (f"Translation to { lang_name } complete. Check the '{ lang_code } .json' file." )
89
+ print (f"Added { len (new_entries )} new entries and removed { len (unused_keys )} unused entries." )
79
90
80
91
if __name__ == '__main__' :
81
92
main ()
82
-
0 commit comments