From 0b7fb139c4f67fd2a51e20e33fc5e02a11be5caa Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 1 Jul 2020 12:51:05 -0700 Subject: [PATCH] noVNC language is now sync'ed with MeshCentral. --- public/novnc/app/localization.js | 4 +++- public/novnc/app/ui.js | 3 ++- views/default.handlebars | 2 +- webserver.js | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/public/novnc/app/localization.js b/public/novnc/app/localization.js index 100901c9..3764b981 100644 --- a/public/novnc/app/localization.js +++ b/public/novnc/app/localization.js @@ -20,9 +20,11 @@ export class Localizer { } // Configure suitable language based on user preferences - setup(supportedLanguages) { + setup(supportedLanguages, language) { this.language = 'en'; // Default: US English + if (language != null) { this.language = language; return; } + /* * Navigator.languages only available in Chrome (32+) and FireFox (32+) * Fall back to navigator.language for other browsers diff --git a/public/novnc/app/ui.js b/public/novnc/app/ui.js index 0b38a1e3..40a972dd 100644 --- a/public/novnc/app/ui.js +++ b/public/novnc/app/ui.js @@ -1658,7 +1658,8 @@ const UI = { // Set up translations const LINGUAS = ["cs", "de", "el", "es", "ko", "nl", "pl", "ru", "sv", "tr", "zh_CN", "zh_TW"]; -l10n.setup(LINGUAS); +if (urlargs.l == "zh-chs") { urlargs.l = "zh_CN"; } +l10n.setup(LINGUAS, urlargs.l); if (l10n.language === "en" || l10n.dictionary !== undefined) { UI.prime(); } else { diff --git a/views/default.handlebars b/views/default.handlebars index 3a3df502..d063e85b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2270,7 +2270,7 @@ newWindow.opener = null; } } else if (message.tag == 'novnc') { - var vncurl = window.location.origin + domainUrl + 'novnc/vnc.html?ws=wss%3A%2F%2F' + window.location.host + '%2Fmeshrelay.ashx%3Fauth%3D' + message.cookie + '&show_dot=1' + (urlargs.key?('&key=' + urlargs.key):''); + var vncurl = window.location.origin + domainUrl + 'novnc/vnc.html?ws=wss%3A%2F%2F' + window.location.host + '%2Fmeshrelay.ashx%3Fauth%3D' + message.cookie + '&show_dot=1' + (urlargs.key?('&key=' + urlargs.key):'') + '&l={{{lang}}}'; var node = getNodeFromId(message.nodeid); if (node != null) { vncurl += '&name=' + encodeURIComponentEx(node.name); } var newWindow = window.open(vncurl, 'mcnovnc/' + message.nodeid); diff --git a/webserver.js b/webserver.js index 8061160f..8b796d4c 100644 --- a/webserver.js +++ b/webserver.js @@ -5823,11 +5823,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { var fileOptions = obj.renderPages[obj.path.basename(filename)]; if (fileOptions != null) { for (var i in acceptLanguages) { - if ((acceptLanguages[i] == 'en') || (acceptLanguages[i].startsWith('en-'))) { break; } // English requested, break out. + if ((acceptLanguages[i] == 'en') || (acceptLanguages[i].startsWith('en-'))) { args.lang = 'en'; break; } // English requested, break out. if (fileOptions[acceptLanguages[i]] != null) { // Found a match. If the file no longer exists, default to English. obj.fs.exists(fileOptions[acceptLanguages[i]] + '.handlebars', function (exists) { - if (exists) { args.lang = acceptLanguages[i]; res.render(fileOptions[acceptLanguages[i]], args); } else { res.render(filename, args); } + if (exists) { args.lang = acceptLanguages[i]; res.render(fileOptions[acceptLanguages[i]], args); } else { args.lang = 'en'; res.render(filename, args); } }); return; }