-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate_translation_file.py
39 lines (32 loc) · 1.28 KB
/
generate_translation_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
try:
print("Fetching translation file...")
translation_file = open("./app/src/main/assets/localization_en.json")
translation_str = translation_file.read()
translation_dict = json.loads(translation_str)
print("Creating class structure...")
translation_class_str = """package com.pradyotprakash.exchangerate.app.localization
/**
* The translation key classes which holds the values of the string keys which is
* required to be shown.
*
* NOTE: This is auto-generated and edited by a script, any manual modification will be overwritten.
*/
object TR {
{values}
}
"""
print("Creating translation values...")
translation_values = ""
for key in translation_dict.keys():
translation_values += f"""var {key} = Translation.getString("{key}")
"""
print("Appending translation values into the class...")
final_translation_class = translation_class_str.replace("{values}", translation_values)
print("Adding class final result into kotlin file...")
translation_kotlin_file = "./app/src/main/java/com/pradyotprakash/exchangerate/app/localization/TR.kt"
with open(translation_kotlin_file, mode="w") as f:
f.write(final_translation_class)
print("Done creating translation file...")
except Exception as e:
print(e)