mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add json sort script
This commit is contained in:
parent
9036d7a073
commit
69fcdfddf0
1
.gitignore
vendored
1
.gitignore
vendored
@ -37,3 +37,4 @@ app/config/
|
|||||||
docker/*
|
docker/*
|
||||||
!docker/docker-compose.yml
|
!docker/docker-compose.yml
|
||||||
lang_sort_log.txt
|
lang_sort_log.txt
|
||||||
|
lang_sort.txt
|
||||||
|
72
.gitlab/scripts/sort.py
Normal file
72
.gitlab/scripts/sort.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_missing_keys_and_values(obj1, obj2, path=None):
|
||||||
|
if path is None:
|
||||||
|
path = []
|
||||||
|
|
||||||
|
missing_keys_and_values = {}
|
||||||
|
|
||||||
|
if isinstance(obj1, dict) and isinstance(obj2, dict):
|
||||||
|
for key in obj1:
|
||||||
|
if key not in obj2:
|
||||||
|
missing_keys_and_values[key] = obj1[key]
|
||||||
|
elif isinstance(obj1[key], (dict, list)) and isinstance(
|
||||||
|
obj2[key], (dict, list)
|
||||||
|
):
|
||||||
|
sub_missing = get_missing_keys_and_values(
|
||||||
|
obj1[key], obj2[key], path + [key]
|
||||||
|
)
|
||||||
|
if sub_missing:
|
||||||
|
missing_keys_and_values[key] = sub_missing
|
||||||
|
|
||||||
|
return missing_keys_and_values
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
project_dir = os.getcwd()
|
||||||
|
os.chdir("../../app/translations") # Change the working directory
|
||||||
|
dir_path = os.getcwd() # Get the current working directory
|
||||||
|
|
||||||
|
en_en_path = os.path.join(dir_path, "en_EN.json")
|
||||||
|
|
||||||
|
if not os.path.isfile(en_en_path):
|
||||||
|
print(
|
||||||
|
f"The file en_EN.json does not exist in {dir_path}. Ensure you have the right directory, Exiting."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
result = {} # JSON object to store missing keys and values
|
||||||
|
|
||||||
|
for root, _, files in os.walk(dir_path):
|
||||||
|
for file in files:
|
||||||
|
if (
|
||||||
|
"_incomplete" not in file
|
||||||
|
and file != "en_EN.json"
|
||||||
|
and file.endswith(".json")
|
||||||
|
):
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
|
||||||
|
with open(file_path, "r", encoding="utf-8") as current_file:
|
||||||
|
current_data = json.load(current_file)
|
||||||
|
|
||||||
|
with open(en_en_path, "r", encoding="utf-8") as en_en_file:
|
||||||
|
en_en_data = json.load(en_en_file)
|
||||||
|
|
||||||
|
missing_keys_and_values = get_missing_keys_and_values(
|
||||||
|
en_en_data, current_data
|
||||||
|
)
|
||||||
|
if missing_keys_and_values:
|
||||||
|
result[file] = missing_keys_and_values
|
||||||
|
|
||||||
|
# Write the JSON object to lang_sort.txt
|
||||||
|
with open(
|
||||||
|
os.path.join(project_dir, "lang_sort.txt"),
|
||||||
|
"w",
|
||||||
|
encoding="utf-8",
|
||||||
|
) as output_file:
|
||||||
|
json.dump(result, output_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
@ -588,6 +588,15 @@
|
|||||||
"newServer": "Create New Server",
|
"newServer": "Create New Server",
|
||||||
"servers": "Servers"
|
"servers": "Servers"
|
||||||
},
|
},
|
||||||
|
"startup": {
|
||||||
|
"starting": "Crafty Is Starting...",
|
||||||
|
"serverInit": "Initializing Servers",
|
||||||
|
"server": "Initializing ",
|
||||||
|
"internet": "Checking for internet connection",
|
||||||
|
"tasks": "Starting Tasks Scheduler",
|
||||||
|
"internals": "Configuring and starting Crafty's internal components",
|
||||||
|
"almost": "Finishing up. Hang on tight..."
|
||||||
|
},
|
||||||
"userConfig": {
|
"userConfig": {
|
||||||
"apiKey": "API Keys",
|
"apiKey": "API Keys",
|
||||||
"auth": "Authorized? ",
|
"auth": "Authorized? ",
|
||||||
|
Loading…
Reference in New Issue
Block a user