Updated translation support

Bryan Roe committed Dec 16, 2020 at 12:03 UTC 92d60dbfbed6ad308608fcebfeaef5f25e9c5f2e
1 file changed +103 -37
agents/meshinstall-linux.js
+103 -37
@@ -14,12 +14,74 @@ See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 -
17 +Object.defineProperty(Array.prototype, 'getParameterEx',
18 + {
19 + value: function (name, defaultValue)
20 + {
21 + var i, ret;
22 + for (i = 0; i < this.length; ++i)
23 + {
24 + if (this[i] == name) { return (null); }
25 + if (this[i].startsWith(name + '='))
26 + {
27 + ret = this[i].substring(name.length + 1);
28 + if (ret.startsWith('"')) { ret = ret.substring(1, ret.length - 1); }
29 + return (ret);
30 + }
31 + }
32 + return (defaultValue);
33 + }
34 + });
35 +Object.defineProperty(Array.prototype, 'getParameter',
36 + {
37 + value: function (name, defaultValue)
38 + {
39 + return (this.getParameterEx('-' + name, defaultValue));
40 + }
41 + });
42
43 // The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings.
44 var msh = {};
45 +메시 에이전트를 설치 또는 제거하려면 아래 버튼을 클릭하십시오. 이 프로그램은 설치하면 백그라운드에서 실행되므로 원격 관리자가이 컴퓨터를 관리하고 제어 할 수 있습니다.\"},\"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\":\"取消\"}}"};
46 +var translation = JSON.parse(msh.translation);
47 +
48 +var lang = require('util-language').current;
49 +if (lang == null) { lang = 'en'; }
50 +if (process.argv.getParameter('lang', lang) == null)
51 +{
52 + console.log('\nCurrent Language: ' + lang + '\n');
53 + process.exit();
54 +}
55 +else
56 +{
57 + lang = process.argv.getParameter('lang', lang).toLowerCase();
58 + lang = lang.split('_').join('-');
59 + if (translation[lang] == null)
60 + {
61 + if (translation[lang.split('-')[0]] == null)
62 + {
63 + console.log('Language: ' + lang + ' is not translated.');
64 + process.exit();
65 + }
66 + else
67 + {
68 + lang = lang.split('-')[0];
69 + }
70 + }
71 +}
72 +
73 +if (lang != 'en')
74 +{
75 + for (var i in translation['en'])
76 + {
77 + // If translated entries are missing, substitute the english translation
78 + if (translation[lang][i] == null) { translation[lang][i] = translation['en'][i]; }
79 + }
80 +}
81 +
82 +
83 var displayName = msh.displayName ? msh.displayName : 'MeshCentral Agent';
22 -var s = null, buttons = ['Cancel'], skip = false;
84 +var s = null, buttons = [translation[lang].cancel], skip = false;
85 var serviceName = msh.meshServiceName ? msh.meshServiceName : 'meshagent';
86
87 try { s = require('service-manager').manager.getService(serviceName); } catch (e) { }
@@ -84,10 +146,14 @@ if (process.argv.includes('-mesh'))
146 console.log(JSON.stringify(msh, null, 2));
147 process.exit();
148 }
87 -
149 +if (process.argv.includes('-translations'))
150 +{
151 + console.log(JSON.stringify(translation));
152 + process.exit();
153 +}
154 if (process.argv.includes('-help'))
155 {
90 - console.log("\nYou can run the text version from the command line with the following command(s): ");
156 + console.log("\n" + translation[lang].commands + ": ");
157 if ((msh.InstallFlags & 1) == 1)
158 {
159 console.log('./' + process.execPath.split('/').pop() + ' -connect');
@@ -111,7 +177,7 @@ if (process.argv.includes('-help'))
177
178 if ((msh.InstallFlags & 1) == 1)
179 {
114 - buttons.unshift('Connect');
180 + buttons.unshift(translation[lang].connect);
181 if (process.argv.includes('-connect'))
182 {
183 global._child = require('child_process').execFile(process.execPath, connectArgs);
@@ -119,9 +185,9 @@ if ((msh.InstallFlags & 1) == 1)
185 global._child.stderr.on('data', function (c) { });
186 global._child.on('exit', function (code) { process.exit(code); });
187
122 - console.log("\nConnecting to: " + msh.MeshServer);
123 - console.log("Device Group: " + msh.MeshName);
124 - console.log('\nPress Ctrl-C to exit\n');
188 + console.log("\n" + translation[lang].url + ": " + msh.MeshServer);
189 + console.log(translation[lang].group + ": " + msh.MeshName);
190 + console.log('\n' + translation[lang].ctrlc + '\n');
191 skip = true;
192 }
193 }
@@ -130,23 +196,23 @@ if ((!skip) && ((msh.InstallFlags & 2) == 2))
196 {
197 if (!require('user-sessions').isRoot())
198 {
133 - console.log('\n' + "Elevated permissions is required to install/uninstall the agent.");
134 - console.log("Please try again with sudo.");
199 + console.log('\n' + translation[lang].elevation);
200 + console.log(translation[lang].sudo);
201 process.exit();
202 }
203 if (s)
204 {
205 if ((process.platform == 'darwin') || require('message-box').kdialog)
206 {
141 - buttons.unshift("Setup");
207 + buttons.unshift(translation[lang].setup);
208 } else
209 {
144 - buttons.unshift("Uninstall");
145 - buttons.unshift("Update");
210 + buttons.unshift(translation[lang].uninstall);
211 + buttons.unshift(translation[lang].update);
212 }
213 } else
214 {
149 - buttons.unshift("Install");
215 + buttons.unshift(translation[lang].install);
216 }
217 }
218
@@ -176,9 +242,9 @@ if (!skip)
242 {
243 if (!require('message-box').kdialog && ((require('message-box').zenity == null) || (!require('message-box').zenity.extra)))
244 {
179 - console.log('\n' + "The graphical version of this installer cannot run on this system.");
180 - console.log("Try installing/updating Zenity, and run again." + '\n');
181 - console.log("You can also run the text version from the command line with the following command(s): ");
245 + console.log('\n' + translation[lang].graphicalerror + '.');
246 + console.log(translation[lang].zenity + ".\n");
247 + console.log(translation[lang].commands + ": ");
248 if ((msh.InstallFlags & 1) == 1)
249 {
250 console.log('./' + process.execPath.split('/').pop() + ' -connect');
@@ -203,7 +269,7 @@ if (!skip)
269 }
270 else
271 {
206 - if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
272 + if (!require('user-sessions').isRoot()) { console.log('\n' + translation[lang].elevation); process.exit(); }
273 }
274 }
275
@@ -212,34 +278,34 @@ if (!skip)
278 {
279 if (!s)
280 {
215 - msg = "Agent: " + "NOT INSTALLED" + '\n';
281 + msg = translation[lang].agent + ": " + translation[lang].status[0] + '\n';
282 } else
283 {
218 - msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
284 + msg = translation[lang].agent + ": " + (s.isRunning() ? translation[lang].status[1] : translation[lang].status[2]) + '\n';
285 }
286
221 - msg += ("Device Group: " + msh.MeshName + '\n');
222 - msg += ("Server URL: " + msh.MeshServer + '\n');
287 + msg += (translation[lang].group + ": " + msh.MeshName + '\n');
288 + msg += (translation[lang].url + ": " + msh.MeshServer + '\n');
289
224 - var p = require('message-box').create(displayName + " Setup", msg, 99999, buttons);
290 + var p = require('message-box').create(displayName + " " + translation[lang].setup, msg, 99999, buttons);
291 p.then(function (v)
292 {
293 switch (v)
294 {
229 - case "Cancel":
295 + case translation[lang].cancel:
296 process.exit();
297 break;
232 - case 'Setup':
233 - var d = require('message-box').create(displayName, msg, 99999, ['Update', 'Uninstall', 'Cancel']);
298 + case translation[lang].setup:
299 + var d = require('message-box').create(displayName, msg, 99999, [translation[lang].update, translation[lang].uninstall, translation[lang].cancel]);
300 d.then(function (v)
301 {
302 switch (v)
303 {
238 - case 'Update':
239 - case 'Install':
304 + case translation[lang].update:
305 + case translation[lang].install:
306 _install();
307 break;
242 - case 'Uninstall':
308 + case translation[lang].uninstall:
309 _uninstall();
310 break;
311 default:
@@ -248,32 +314,32 @@ if (!skip)
314 process.exit();
315 }).catch(function (v) { process.exit(); });
316 break;
251 - case "Connect":
317 + case translation[lang].connect:
318 global._child = require('child_process').execFile(process.execPath, connectArgs);
319 global._child.stdout.on('data', function (c) { });
320 global._child.stderr.on('data', function (c) { });
321 global._child.on('exit', function (code) { process.exit(code); });
322
257 - msg = ("Device Group: " + msh.MeshName + '\n');
258 - msg += ("Server URL: " + msh.MeshServer + '\n');
323 + msg = (translation[lang].group + ": " + msh.MeshName + '\n');
324 + msg += (translation[lang].url + ": " + msh.MeshServer + '\n');
325
326 if (process.platform != 'darwin')
327 {
328 if (!require('message-box').zenity && require('message-box').kdialog)
329 {
264 - msg += ('\nPress OK to Disconnect');
330 + msg += ('\n' + translation[lang].pressok);
331 }
332 }
333
268 - var d = require('message-box').create(displayName, msg, 99999, ['Disconnect']);
334 + var d = require('message-box').create(displayName, msg, 99999, [translation[lang].disconnect]);
335 d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
336 break;
271 - case "Uninstall":
337 + case translation[lang].uninstall:
338 _uninstall();
339 process.exit();
340 break;
275 - case "Install":
276 - case "Update":
341 + case translation[lang].install:
342 + case translation[lang].update:
343 _install();
344 process.exit();
345 break;