Merge branch 'language-update' into 'dev'

Allows translation on start error messages.

See merge request crafty-controller/crafty-commander!81
This commit is contained in:
Andrew 2021-09-30 01:58:42 +00:00
commit 1031c1b1f8
2 changed files with 13 additions and 12 deletions

View File

@ -134,9 +134,9 @@ class Server:
# remove the scheduled job since it's ran # remove the scheduled job since it's ran
return schedule.CancelJob return schedule.CancelJob
def run_threaded_server(self): def run_threaded_server(self, lang):
# start the server # start the server
self.server_thread = threading.Thread(target=self.start_server, daemon=True, name='{}_server_thread'.format(self.server_id)) self.server_thread = threading.Thread(target=self.start_server, daemon=True, args=(lang,), name='{}_server_thread'.format(self.server_id))
self.server_thread.start() self.server_thread.start()
def setup_server_run_command(self): def setup_server_run_command(self):
@ -161,7 +161,7 @@ class Server:
console.warning("Unable to write/access {}".format(self.server_path)) console.warning("Unable to write/access {}".format(self.server_path))
helper.do_exit() helper.do_exit()
def start_server(self): def start_server(self, user_lang):
logger.info("Start command detected. Reloading settings from DB for server {}".format(self.name)) logger.info("Start command detected. Reloading settings from DB for server {}".format(self.name))
self.setup_server_run_command() self.setup_server_run_command()
@ -193,7 +193,7 @@ class Server:
msg = "Server {} failed to start with error code: {}".format(self.name, ex) msg = "Server {} failed to start with error code: {}".format(self.name, ex)
logger.error(msg) logger.error(msg)
websocket_helper.broadcast('send_start_error', { websocket_helper.broadcast('send_start_error', {
'error': translation.translate('error', 'start-error', 'en_EN').format(self.name, ex) 'error': translation.translate('error', 'start-error', user_lang).format(self.name, ex)
}) })
return False return False
if helper.check_internet(): if helper.check_internet():
@ -203,11 +203,11 @@ class Server:
}) })
else: else:
websocket_helper.broadcast('send_start_error', { websocket_helper.broadcast('send_start_error', {
'error': translation.translate('error', 'closedPort', 'en_EN').format(loc_server_port) 'error': translation.translate('error', 'closedPort', user_lang).format(loc_server_port)
}) })
else: else:
websocket_helper.broadcast('send_start_error', { websocket_helper.broadcast('send_start_error', {
'error': translation.translate('error', 'internet', 'en_EN') 'error': translation.translate('error', 'internet', user_lang)
}) })
logger.debug('Starting virtual terminal listener for server {}'.format(self.name)) logger.debug('Starting virtual terminal listener for server {}'.format(self.name))
@ -275,15 +275,15 @@ class Server:
self.stats.record_stats() self.stats.record_stats()
def restart_threaded_server(self): def restart_threaded_server(self, lang):
# if not already running, let's just start # if not already running, let's just start
if not self.check_running(): if not self.check_running():
self.run_threaded_server() self.run_threaded_server(lang)
else: else:
self.stop_threaded_server() self.stop_threaded_server()
time.sleep(2) time.sleep(2)
self.run_threaded_server() self.run_threaded_server(lang)
def cleanup_server_object(self): def cleanup_server_object(self):
self.PID = None self.PID = None

View File

@ -98,22 +98,23 @@ class TasksManager:
for c in commands: for c in commands:
svr = self.controller.get_server_obj(c['server_id']['server_id']) svr = self.controller.get_server_obj(c['server_id']['server_id'])
user_lang = c.get('user')['lang']
command = c.get('command', None) command = c.get('command', None)
if command == 'start_server': if command == 'start_server':
svr.run_threaded_server() svr.run_threaded_server(user_lang)
elif command == 'stop_server': elif command == 'stop_server':
svr.stop_threaded_server() svr.stop_threaded_server()
elif command == "restart_server": elif command == "restart_server":
svr.restart_threaded_server() svr.restart_threaded_server(user_lang)
elif command == "backup_server": elif command == "backup_server":
svr.backup_server() svr.backup_server()
elif command == "update_executable": elif command == "update_executable":
svr.jar_update() svr.jar_update(user_lang)
management_helper.mark_command_complete(c.get('command_id', None)) management_helper.mark_command_complete(c.get('command_id', None))
time.sleep(1) time.sleep(1)