From 52946c3e08f975758dcd2ecde8ecd25d330390be Mon Sep 17 00:00:00 2001 From: Nelson Chan <3271800+chakflying@users.noreply.github.com> Date: Fri, 1 Sep 2023 20:51:28 +0800 Subject: [PATCH] Feat: Translate toast messages by adding msgi18n to callbacks (#3263) * WIP: Add msgTranslated to callbacks * Chore: Unify Saved period * Feat: add support for interpolation --- server/server.js | 10 +++++++--- server/socket-handlers/docker-socket-handler.js | 3 ++- .../socket-handlers/maintenance-socket-handler.js | 1 + server/socket-handlers/proxy-socket-handler.js | 3 ++- src/lang/en.json | 3 ++- src/lang/hr-HR.json | 2 +- src/lang/zh-HK.json | 3 ++- src/mixins/socket.js | 13 +++++++++++-- 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/server/server.js b/server/server.js index d50544bf0..2cf616a9d 100644 --- a/server/server.js +++ b/server/server.js @@ -839,6 +839,7 @@ let needSetup = false; callback({ ok: true, msg: "Saved.", + msgi18n: true, monitorID: bean.id, }); @@ -1066,7 +1067,8 @@ let needSetup = false; callback({ ok: true, - msg: "Saved", + msg: "Saved.", + msgi18n: true, tag: await bean.toJSON(), }); @@ -1260,7 +1262,8 @@ let needSetup = false; callback({ ok: true, - msg: "Saved" + msg: "Saved.", + msgi18n: true, }); sendInfo(socket); @@ -1284,7 +1287,8 @@ let needSetup = false; callback({ ok: true, - msg: "Saved", + msg: "Saved.", + msgi18n: true, id: notificationBean.id, }); diff --git a/server/socket-handlers/docker-socket-handler.js b/server/socket-handlers/docker-socket-handler.js index d7d768f00..6a14294cf 100644 --- a/server/socket-handlers/docker-socket-handler.js +++ b/server/socket-handlers/docker-socket-handler.js @@ -18,7 +18,8 @@ module.exports.dockerSocketHandler = (socket) => { callback({ ok: true, - msg: "Saved", + msg: "Saved.", + msgi18n: true, id: dockerHostBean.id, }); diff --git a/server/socket-handlers/maintenance-socket-handler.js b/server/socket-handlers/maintenance-socket-handler.js index 348c0a3cc..656f5bb24 100644 --- a/server/socket-handlers/maintenance-socket-handler.js +++ b/server/socket-handlers/maintenance-socket-handler.js @@ -61,6 +61,7 @@ module.exports.maintenanceSocketHandler = (socket) => { callback({ ok: true, msg: "Saved.", + msgi18n: true, maintenanceID: bean.id, }); diff --git a/server/socket-handlers/proxy-socket-handler.js b/server/socket-handlers/proxy-socket-handler.js index a5f2f4787..eb8c5c866 100644 --- a/server/socket-handlers/proxy-socket-handler.js +++ b/server/socket-handlers/proxy-socket-handler.js @@ -24,7 +24,8 @@ module.exports.proxySocketHandler = (socket) => { callback({ ok: true, - msg: "Saved", + msg: "Saved.", + msgi18n: true, id: proxyBean.id, }); diff --git a/src/lang/en.json b/src/lang/en.json index 8a0985781..d75954a0f 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -812,5 +812,6 @@ "showCertificateExpiry": "Show Certificate Expiry", "noOrBadCertificate": "No/Bad Certificate", "gamedigGuessPort": "Gamedig: Guess Port", - "gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server." + "gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.", + "Saved.": "Saved." } diff --git a/src/lang/hr-HR.json b/src/lang/hr-HR.json index 40057a65d..f14ffd204 100644 --- a/src/lang/hr-HR.json +++ b/src/lang/hr-HR.json @@ -348,7 +348,7 @@ "Discard": "Odbaci", "Cancel": "Otkaži", "Powered by": "Pokreće", - "Saved": "Spremljeno", + "Saved.": "Spremljeno.", "PushByTechulus": "Push by Techulus", "GoogleChat": "Google Chat (preko platforme Google Workspace)", "shrinkDatabaseDescription": "Pokreni VACUUM operaciju za SQLite. Ako je baza podataka kreirana nakon inačice 1.10.0, AUTO_VACUUM opcija već je uključena te ova akcija nije nužna.", diff --git a/src/lang/zh-HK.json b/src/lang/zh-HK.json index e4b10eb56..7c0b9c4f5 100644 --- a/src/lang/zh-HK.json +++ b/src/lang/zh-HK.json @@ -730,5 +730,6 @@ "Invert Keyword": "以上關鍵字不能出現", "Home": "首頁", "Expected Value": "預期值", - "Json Query": "JSON 查询" + "Json Query": "JSON 查询", + "Saved.": "已儲存。" } diff --git a/src/mixins/socket.js b/src/mixins/socket.js index d07993e23..73da7794f 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -330,10 +330,19 @@ export default { * @returns {void} */ toastRes(res) { + let msg = res.msg; + if (res.msgi18n) { + if (msg != null && typeof msg === "object") { + msg = this.$t(msg.key, msg.values); + } else { + msg = this.$t(msg); + } + } + if (res.ok) { - toast.success(res.msg); + toast.success(msg); } else { - toast.error(res.msg); + toast.error(msg); } },