Updated translation support

This commit is contained in:
Bryan Roe 2020-12-16 12:03:02 -08:00
parent 22beb63562
commit 92d60dbfbe

View File

@ -14,12 +14,74 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
Object.defineProperty(Array.prototype, 'getParameterEx',
{
value: function (name, defaultValue)
{
var i, ret;
for (i = 0; i < this.length; ++i)
{
if (this[i] == name) { return (null); }
if (this[i].startsWith(name + '='))
{
ret = this[i].substring(name.length + 1);
if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); }
return (ret);
}
}
return (defaultValue);
}
});
Object.defineProperty(Array.prototype, 'getParameter',
{
value: function (name, defaultValue)
{
return (this.getParameterEx('-' + name, defaultValue));
}
});
// The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings. // The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings.
var msh = {}; var msh = {};
메시 에이전트를 설치 또는 제거하려면 아래 버튼을 클릭하십시오. 프로그램은 설치하면 백그라운드에서 실행되므로 원격 관리자가이 컴퓨터를 관리하고 제어 있습니다.\"},\"nl\":{\"agent\":\"Agent\",\"agentVersion\":\"Nieuwe agent versie\",\"group\":\"Apparaat groep\",\"url\":\"Server URL\",\"meshName\":\"Mesh naam\",\"meshId\":\"Mesh identificatie\",\"serverId\":\"Server identificatie\",\"setup\":\"Setup\",\"update\":\"Bijwerken\",\"install\":\"Installeren\",\"uninstall\":\"Deïnstallatie\",\"connect\":\"Verbinden\",\"disconnect\":\"Verbreken\",\"cancel\":\"Annuleren\",\"pressok\":\"Druk op OK om de verbinding te verbreken\",\"elevation\":\"Verhoogde machtigingen zijn vereist om de agent te installeren / verwijderen.\",\"sudo\":\"Probeer het opnieuw met sudo.\",\"ctrlc\":\"Druk op Ctrl-C om af te sluiten.\",\"commands\":\"U kunt de tekstversie vanaf de opdrachtregel uitvoeren met de volgende opdracht(en)\",\"zenity\":\"Probeer Zenity te installeren / bij te werken en voer het opnieuw uit\",\"status\":[\"NIET GEÏNSTALLEERD\",\"ACTIEF\",\"NIET ACTIEF\"],\"statusDescription\":\"Huidige agent status\",\"description\":\"Klik op de onderstaande knoppen om de mesh-agent te installeren of te verwijderen. Na installatie wordt deze software op de achtergrond uitgevoerd, zodat deze computer kan worden beheerd en bestuurd door een externe beheerder.\"},\"pt\":{\"agent\":\"Agente\",\"group\":\"Grupo de dispositivos\",\"install\":\"Instalar\",\"uninstall\":\"Desinstalar\",\"connect\":\"Conectar\",\"disconnect\":\"Desconectar\",\"cancel\":\"Cancelar\"},\"ru\":{\"agent\":\"Агент\",\"group\":\"Группа устройства\",\"install\":\"Установка\",\"uninstall\":\"Удаление\",\"connect\":\"Подключиться\",\"disconnect\":\"Разъединить\",\"cancel\":\"Отмена\"},\"tr\":{\"agent\":\"Ajan\",\"group\":\"Cihaz Grubu\",\"install\":\"Yüklemek\",\"uninstall\":\"Kaldır\",\"connect\":\"Bağlan\",\"disconnect\":\"Bağlantıyı kes\",\"cancel\":\"İptal etmek\"},\"zh-hans\":{\"agent\":\"代理\",\"group\":\"设备组\",\"install\":\"安装\",\"uninstall\":\"卸载\",\"connect\":\"连接\",\"disconnect\":\"断线\",\"cancel\":\"取消\"},\"zh-hant\":{\"agent\":\"代理\",\"group\":\"裝置群\",\"install\":\"安裝\",\"uninstall\":\"卸載\",\"connect\":\"連接\",\"disconnect\":\"斷線\",\"cancel\":\"取消\"}}"};
var translation = JSON.parse(msh.translation);
var lang = require('util-language').current;
if (lang == null) { lang = 'en'; }
if (process.argv.getParameter('lang', lang) == null)
{
console.log('\nCurrent Language: ' + lang + '\n');
process.exit();
}
else
{
lang = process.argv.getParameter('lang', lang).toLowerCase();
lang = lang.split('_').join('-');
if (translation[lang] == null)
{
if (translation[lang.split('-')[0]] == null)
{
console.log('Language: ' + lang + ' is not translated.');
process.exit();
}
else
{
lang = lang.split('-')[0];
}
}
}
if (lang != 'en')
{
for (var i in translation['en'])
{
// If translated entries are missing, substitute the english translation
if (translation[lang][i] == null) { translation[lang][i] = translation['en'][i]; }
}
}
var displayName = msh.displayName ? msh.displayName : 'MeshCentral Agent'; var displayName = msh.displayName ? msh.displayName : 'MeshCentral Agent';
var s = null, buttons = ['Cancel'], skip = false; var s = null, buttons = [translation[lang].cancel], skip = false;
var serviceName = msh.meshServiceName ? msh.meshServiceName : 'meshagent'; var serviceName = msh.meshServiceName ? msh.meshServiceName : 'meshagent';
try { s = require('service-manager').manager.getService(serviceName); } catch (e) { } try { s = require('service-manager').manager.getService(serviceName); } catch (e) { }
@ -84,10 +146,14 @@ if (process.argv.includes('-mesh'))
console.log(JSON.stringify(msh, null, 2)); console.log(JSON.stringify(msh, null, 2));
process.exit(); process.exit();
} }
if (process.argv.includes('-translations'))
{
console.log(JSON.stringify(translation));
process.exit();
}
if (process.argv.includes('-help')) if (process.argv.includes('-help'))
{ {
console.log("\nYou can run the text version from the command line with the following command(s): "); console.log("\n" + translation[lang].commands + ": ");
if ((msh.InstallFlags & 1) == 1) if ((msh.InstallFlags & 1) == 1)
{ {
console.log('./' + process.execPath.split('/').pop() + ' -connect'); console.log('./' + process.execPath.split('/').pop() + ' -connect');
@ -111,7 +177,7 @@ if (process.argv.includes('-help'))
if ((msh.InstallFlags & 1) == 1) if ((msh.InstallFlags & 1) == 1)
{ {
buttons.unshift('Connect'); buttons.unshift(translation[lang].connect);
if (process.argv.includes('-connect')) if (process.argv.includes('-connect'))
{ {
global._child = require('child_process').execFile(process.execPath, connectArgs); global._child = require('child_process').execFile(process.execPath, connectArgs);
@ -119,9 +185,9 @@ if ((msh.InstallFlags & 1) == 1)
global._child.stderr.on('data', function (c) { }); global._child.stderr.on('data', function (c) { });
global._child.on('exit', function (code) { process.exit(code); }); global._child.on('exit', function (code) { process.exit(code); });
console.log("\nConnecting to: " + msh.MeshServer); console.log("\n" + translation[lang].url + ": " + msh.MeshServer);
console.log("Device Group: " + msh.MeshName); console.log(translation[lang].group + ": " + msh.MeshName);
console.log('\nPress Ctrl-C to exit\n'); console.log('\n' + translation[lang].ctrlc + '\n');
skip = true; skip = true;
} }
} }
@ -130,23 +196,23 @@ if ((!skip) && ((msh.InstallFlags & 2) == 2))
{ {
if (!require('user-sessions').isRoot()) if (!require('user-sessions').isRoot())
{ {
console.log('\n' + "Elevated permissions is required to install/uninstall the agent."); console.log('\n' + translation[lang].elevation);
console.log("Please try again with sudo."); console.log(translation[lang].sudo);
process.exit(); process.exit();
} }
if (s) if (s)
{ {
if ((process.platform == 'darwin') || require('message-box').kdialog) if ((process.platform == 'darwin') || require('message-box').kdialog)
{ {
buttons.unshift("Setup"); buttons.unshift(translation[lang].setup);
} else } else
{ {
buttons.unshift("Uninstall"); buttons.unshift(translation[lang].uninstall);
buttons.unshift("Update"); buttons.unshift(translation[lang].update);
} }
} else } else
{ {
buttons.unshift("Install"); buttons.unshift(translation[lang].install);
} }
} }
@ -176,9 +242,9 @@ if (!skip)
{ {
if (!require('message-box').kdialog && ((require('message-box').zenity == null) || (!require('message-box').zenity.extra))) if (!require('message-box').kdialog && ((require('message-box').zenity == null) || (!require('message-box').zenity.extra)))
{ {
console.log('\n' + "The graphical version of this installer cannot run on this system."); console.log('\n' + translation[lang].graphicalerror + '.');
console.log("Try installing/updating Zenity, and run again." + '\n'); console.log(translation[lang].zenity + ".\n");
console.log("You can also run the text version from the command line with the following command(s): "); console.log(translation[lang].commands + ": ");
if ((msh.InstallFlags & 1) == 1) if ((msh.InstallFlags & 1) == 1)
{ {
console.log('./' + process.execPath.split('/').pop() + ' -connect'); console.log('./' + process.execPath.split('/').pop() + ' -connect');
@ -203,7 +269,7 @@ if (!skip)
} }
else else
{ {
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); } if (!require('user-sessions').isRoot()) { console.log('\n' + translation[lang].elevation); process.exit(); }
} }
} }
@ -212,34 +278,34 @@ if (!skip)
{ {
if (!s) if (!s)
{ {
msg = "Agent: " + "NOT INSTALLED" + '\n'; msg = translation[lang].agent + ": " + translation[lang].status[0] + '\n';
} else } else
{ {
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n'; msg = translation[lang].agent + ": " + (s.isRunning() ? translation[lang].status[1] : translation[lang].status[2]) + '\n';
} }
msg += ("Device Group: " + msh.MeshName + '\n'); msg += (translation[lang].group + ": " + msh.MeshName + '\n');
msg += ("Server URL: " + msh.MeshServer + '\n'); msg += (translation[lang].url + ": " + msh.MeshServer + '\n');
var p = require('message-box').create(displayName + " Setup", msg, 99999, buttons); var p = require('message-box').create(displayName + " " + translation[lang].setup, msg, 99999, buttons);
p.then(function (v) p.then(function (v)
{ {
switch (v) switch (v)
{ {
case "Cancel": case translation[lang].cancel:
process.exit(); process.exit();
break; break;
case 'Setup': case translation[lang].setup:
var d = require('message-box').create(displayName, msg, 99999, ['Update', 'Uninstall', 'Cancel']); var d = require('message-box').create(displayName, msg, 99999, [translation[lang].update, translation[lang].uninstall, translation[lang].cancel]);
d.then(function (v) d.then(function (v)
{ {
switch (v) switch (v)
{ {
case 'Update': case translation[lang].update:
case 'Install': case translation[lang].install:
_install(); _install();
break; break;
case 'Uninstall': case translation[lang].uninstall:
_uninstall(); _uninstall();
break; break;
default: default:
@ -248,32 +314,32 @@ if (!skip)
process.exit(); process.exit();
}).catch(function (v) { process.exit(); }); }).catch(function (v) { process.exit(); });
break; break;
case "Connect": case translation[lang].connect:
global._child = require('child_process').execFile(process.execPath, connectArgs); global._child = require('child_process').execFile(process.execPath, connectArgs);
global._child.stdout.on('data', function (c) { }); global._child.stdout.on('data', function (c) { });
global._child.stderr.on('data', function (c) { }); global._child.stderr.on('data', function (c) { });
global._child.on('exit', function (code) { process.exit(code); }); global._child.on('exit', function (code) { process.exit(code); });
msg = ("Device Group: " + msh.MeshName + '\n'); msg = (translation[lang].group + ": " + msh.MeshName + '\n');
msg += ("Server URL: " + msh.MeshServer + '\n'); msg += (translation[lang].url + ": " + msh.MeshServer + '\n');
if (process.platform != 'darwin') if (process.platform != 'darwin')
{ {
if (!require('message-box').zenity && require('message-box').kdialog) if (!require('message-box').zenity && require('message-box').kdialog)
{ {
msg += ('\nPress OK to Disconnect'); msg += ('\n' + translation[lang].pressok);
} }
} }
var d = require('message-box').create(displayName, msg, 99999, ['Disconnect']); var d = require('message-box').create(displayName, msg, 99999, [translation[lang].disconnect]);
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); }); d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
break; break;
case "Uninstall": case translation[lang].uninstall:
_uninstall(); _uninstall();
process.exit(); process.exit();
break; break;
case "Install": case translation[lang].install:
case "Update": case translation[lang].update:
_install(); _install();
process.exit(); process.exit();
break; break;