-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
add_locale_word.py
75 lines (60 loc) · 2.64 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
66
67
68
69
70
71
72
73
74
75
"""
This script is used to add a new locale word to the project.
Example:
python.bat .\add_locale_word.py -s CliHelp -k ShowHelpMessage -v "k akkalol asdasd asd asd asd"
"""
import sys, os, argparse
# 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, default) -> None:
with open("Jammer.Core/src/Locale.cs", "r", encoding="utf-8") as file:
lines = file.readlines()
with open("Jammer.Core/src/Locale.cs", "w", encoding="utf-8") 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 + '", "' + default + '");\n')
else:
file.write(line)
locales_dir = "locales"
for filename in os.listdir(locales_dir):
if filename.endswith(".ini"):
file_path = os.path.join(locales_dir, filename)
with open(file_path, "r", encoding="utf-8") as file:
ini_lines = file.readlines()
with open(file_path, "w", encoding="utf-8") as file:
for line in ini_lines:
if "[" + key + "]" in line:
file.write(line)
file.write(value + " = " + default + "\n")
else:
file.write(line)
# Add the new key-value pair at the end of the file if not found
if not any("[" + key + "]" in line for line in ini_lines):
file.write(f"\n[{key}]\n{value} = " + default + "\n")
print("New locale word added successfully!")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="This script is used to add a new locale word to the project.")
parser.add_argument(
"--section", "-s",
help="The key for the new locale word")
parser.add_argument(
"--key", "-k",
help="The value for the new locale word")
parser.add_argument(
"--value", "-v", nargs='?', default="Temp Wordings",
help="The default value for the new locale word (optional)")
args = parser.parse_args()
add_locale_word(args.section, args.key, args.value)