-
Notifications
You must be signed in to change notification settings - Fork 1
/
i18n-generator.py
114 lines (103 loc) · 3 KB
/
i18n-generator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import json
from googletrans import Translator
locales = {
"ar": "Arabic",
"am": "Amharic",
"bg": "Bulgarian",
"bn": "Bengali",
"ca": "Catalan",
"cs": "Czech",
"da": "Danish",
"de": "German",
"el": "Greek",
"en": "English",
"en_GB": "English (Great Britain)",
"en_US": "English (USA)",
"es": "Spanish",
"es_419": "Spanish (Latin America and Caribbean)",
"et": "Estonian",
"fa": "Persian",
"fi": "Finnish",
"fil": "Filipino",
"fr": "French",
"gu": "Gujarati",
"he": "Hebrew",
"hi": "Hindi",
"hr": "Croatian",
"hu": "Hungarian",
"id": "Indonesian",
"it": "Italian",
"ja": "Japanese",
"kn": "Kannada",
"ko": "Korean",
"lt": "Lithuanian",
"lv": "Latvian",
"ml": "Malayalam",
"mr": "Marathi",
"ms": "Malay",
"nl": "Dutch",
"no": "Norwegian",
"pl": "Polish",
"pt_BR": "Portuguese (Brazil)",
"pt_PT": "Portuguese (Portugal)",
"ro": "Romanian",
"ru": "Russian",
"sk": "Slovak",
"sl": "Slovenian",
"sr": "Serbian",
"sv": "Swedish",
"sw": "Swahili",
"ta": "Tamil",
"te": "Telugu",
"th": "Thai",
"tr": "Turkish",
"uk": "Ukrainian",
"vi": "Vietnamese",
"zh_CN": "Chinese (China)",
"zh_TW": "Chinese (Taiwan)"
}
default_message = {
"kudo_all": {
"message": "Kudo All"
},
"AppName": {
"message": "GCW and Strava Kudo All"
},
"AppDescription": {
"message": "Give kudos to your elite athletes friends in one click",
}
}
def translate_message(message, target_locale):
translator = Translator()
translated_message = translator.translate(message, dest=target_locale).text
return translated_message
def create_locale_dirs():
base_path = "src/_locales"
if not os.path.exists(base_path):
os.makedirs(base_path)
for code, language in locales.items():
locale_path = os.path.join(base_path, code)
if not os.path.exists(locale_path):
os.makedirs(locale_path)
messages_path = os.path.join(locale_path, "messages.json")
if not os.path.exists(messages_path):
with open(messages_path, "w", encoding="utf-8") as f:
# translated_message = translate_message(
# default_message["kudo_all"]["message"], code)
# translated_AppName = translate_message(
# default_message["AppName"]["message"], code)
# translated_content = {
# "kudo_all": {
# "message": translated_message
# },
# "AppName": {
# "message": translated_AppName
# }
# }
f.write(json.dumps(default_message,
ensure_ascii=False, indent=2))
# f.write(json.dumps(translated_content,
# ensure_ascii=False, indent=2))
if __name__ == "__main__":
create_locale_dirs()