Add user-based translation to startup

This commit is contained in:
amcmanu3 2023-11-30 12:14:09 -05:00
parent b60e6933dd
commit ca02c9d575
4 changed files with 23 additions and 21 deletions

View File

@ -13,7 +13,6 @@ from app.classes.shared.server import ServerInstance
from app.classes.shared.console import Console from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.shared.translation import Translation
from app.classes.minecraft.stats import Stats from app.classes.minecraft.stats import Stats
@ -40,7 +39,6 @@ class ServersController(metaclass=Singleton):
self.stats = Stats(self.helper, self) self.stats = Stats(self.helper, self)
self.ws = WebSocketManager() self.ws = WebSocketManager()
self.server_subpage = {} self.server_subpage = {}
self.translation = Translation(self.helper)
# ********************************************************************************** # **********************************************************************************
# Generic Servers Methods # Generic Servers Methods
@ -174,13 +172,14 @@ class ServersController(metaclass=Singleton):
def init_all_servers(self): def init_all_servers(self):
servers = self.get_all_defined_servers() servers = self.get_all_defined_servers()
self.failed_servers = [] self.failed_servers = []
init_trans = self.translation.translate(
"startup", "server", self.helper.get_setting("language")
)
for server in servers: for server in servers:
self.ws.broadcast_to_admins( self.ws.broadcast_to_admins(
"update", "update",
{"message": f"{init_trans}{server['server_name']}."}, {"section": "server", "server": server["server_name"]},
)
self.ws.broadcast_to_non_admins(
"update",
{"section": "init"},
) )
server_id = server.get("server_id") server_id = server.get("server_id")

View File

@ -15,7 +15,13 @@
<br> <br>
</br> </br>
<div id="text-div" style="width: 100%; text-align: center;"> <div id="text-div" style="width: 100%; text-align: center;">
<h2 id="status" style="display: block;">Crafty Is Starting</h2> <h2 id="status" style="display: block;" data-init="{{ translate('startup', 'serverInit', data['lang']) }}"
data-server="{{ translate('startup', 'server', data['lang']) }}"
data-internet="{{ translate('startup', 'internet', data['lang']) }}"
data-tasks="{{ translate('startup', 'tasks', data['lang']) }}"
data-internals="{{ translate('startup', 'internals', data['lang']) }}"
data-almost="{{ translate('startup', 'almost', data['lang']) }}">
{{ translate('startup', 'starting', data['lang']) }}</h2>
</div> </div>
</div> </div>
@ -48,8 +54,11 @@
}, 2000); }, 2000);
if (webSocket) { if (webSocket) {
webSocket.on('update', function (data) { webSocket.on('update', function (data) {
console.log("got status") if ("server" in data) {
$("#status").html(data.message); $("#status").html(`${$("#status").data(data.section)} ${data.server}...`);
} else {
$("#status").html($("#status").data(data.section));
}
}); });
webSocket.on('send_start_reload', function () { webSocket.on('send_start_reload', function () {
setTimeout(function () { setTimeout(function () {

View File

@ -591,6 +591,7 @@
"servers": "Servers" "servers": "Servers"
}, },
"startup": { "startup": {
"starting": "Crafty Is Starting...",
"serverInit": "Initializing Servers", "serverInit": "Initializing Servers",
"server": "Initializing ", "server": "Initializing ",
"internet": "Checking for internet connection", "internet": "Checking for internet connection",

17
main.py
View File

@ -16,13 +16,10 @@ from app.classes.shared.helpers import Helpers
from app.classes.models.users import HelperUsers from app.classes.models.users import HelperUsers
from app.classes.models.management import HelpersManagement from app.classes.models.management import HelpersManagement
from app.classes.shared.import_helper import ImportHelpers from app.classes.shared.import_helper import ImportHelpers
from app.classes.shared.translation import Translation
from app.classes.shared.websocket_manager import WebSocketManager from app.classes.shared.websocket_manager import WebSocketManager
console = Console() console = Console()
helper = Helpers() helper = Helpers()
translation = Translation(helper)
HOST_LANG = helper.get_setting("language")
# Get the path our application is running on. # Get the path our application is running on.
if getattr(sys, "frozen", False): if getattr(sys, "frozen", False):
APPLICATION_PATH = os.path.dirname(sys.executable) APPLICATION_PATH = os.path.dirname(sys.executable)
@ -199,19 +196,15 @@ def setup_starter():
Console.info("Setting up Crafty's internal components...") Console.info("Setting up Crafty's internal components...")
# Start the setup threads # Start the setup threads
web_sock.broadcast( web_sock.broadcast("update", {"section": "tasks"})
"update", {"message": translation.translate("startup", "tasks", HOST_LANG)}
)
time.sleep(2) time.sleep(2)
tasks_starter_thread.start() tasks_starter_thread.start()
web_sock.broadcast( web_sock.broadcast("update", {"section": "internet"})
"update", {"message": translation.translate("startup", "internet", HOST_LANG)}
)
time.sleep(2) time.sleep(2)
internet_check_thread.start() internet_check_thread.start()
web_sock.broadcast( web_sock.broadcast(
"update", "update",
{"message": translation.translate("startup", "internals", HOST_LANG)}, {"section": "internals"},
) )
time.sleep(2) time.sleep(2)
controller_setup_thread.start() controller_setup_thread.start()
@ -219,7 +212,7 @@ def setup_starter():
# Wait for the setup threads to finish # Wait for the setup threads to finish
web_sock.broadcast( web_sock.broadcast(
"update", "update",
{"message": translation.translate("startup", "almost", HOST_LANG)}, {"section": "almost"},
) )
tasks_starter_thread.join() tasks_starter_thread.join()
internet_check_thread.join() internet_check_thread.join()
@ -388,7 +381,7 @@ if __name__ == "__main__":
Console.info("Initializing all servers defined") Console.info("Initializing all servers defined")
web_sock.broadcast( web_sock.broadcast(
"update", "update",
{"message": translation.translate("startup", "serverInit", HOST_LANG)}, {"section": "serverInit"},
) )
controller.servers.init_all_servers() controller.servers.init_all_servers()