-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
add_locale_word.py
65 lines (52 loc) · 2 KB
/
add_locale_word.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
"""
This script is used to add a new locale word to the project.
Usage:
python add_locale_word.py <key> <value> optional: <default_value>
Example:
python add_locale_word.py "CliHelp" "ShowHelpMessage"
"""
import sys
import os
# public static class Settings
key_start_word = " public static class "
# ??? = CheckValueLocale((string key, string value, string defaultString)
value_start_word = " public static string "
"""
Add a new locale word to the project.
"""
def add_locale_word(key, value) -> None:
with open("Jammer.Core/src/Locale.cs", "r") as file:
lines = file.readlines()
with open("Jammer.Core/src/Locale.cs", "w") as file:
for line in lines:
if key_start_word + key in line:
# append to next line the new value
file.write(line)
file.write(value_start_word +
value +
' = CheckValueLocale(' +
'"' +
key +
'", "' +
value + '", "Temp Wordings"); // TODO Dont leave me here\n')
else:
file.write(line)
with open("locales/en.ini", "r") as file:
ini_lines = file.readlines()
with open("locales/en.ini", "w") as file:
for line in ini_lines:
if "[" + key + "]" in line:
file.write(line)
file.write(value + " = Temp Wordings" + "\n")
else:
file.write(line)
print("New locale word added successfully!")
if __name__ == "__main__":
if len(sys.argv) != 3 and len(sys.argv) != 4:
print("Usage: python add_locale_word.py <key> <value> optional: <default_value>")
sys.exit(1)
key = sys.argv[1]
value = sys.argv[2]
# rest is the default value
default = sys.argv[3] if len(sys.argv) == 4 else "Temp Wordings"
add_locale_word(key, value)