From 2c29909ef6cae43eb59b985422ac987915ab83cd Mon Sep 17 00:00:00 2001 From: cany748 Date: Mon, 20 Jun 2022 20:09:17 +0700 Subject: [PATCH] add environment variable for changes lang --- src/config.js | 1 + src/lib/Server.js | 4 ++++ src/www/index.html | 26 +++++--------------------- src/www/js/api.js | 7 +++++++ src/www/js/app.js | 12 ++++++------ src/www/js/i18n.js | 6 ++---- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/config.js b/src/config.js index 28c9fc5a..8c0c91e0 100644 --- a/src/config.js +++ b/src/config.js @@ -26,3 +26,4 @@ iptables -A FORWARD -o wg0 -j ACCEPT; module.exports.WG_PRE_DOWN = process.env.WG_PRE_DOWN || ''; module.exports.WG_POST_DOWN = process.env.WG_POST_DOWN || ''; +module.exports.LANG = process.env.LANG || 'en'; diff --git a/src/lib/Server.js b/src/lib/Server.js index c893d7d5..0279796f 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -14,6 +14,7 @@ const { PORT, RELEASE, PASSWORD, + LANG, } = require('../config'); module.exports = class Server { @@ -134,6 +135,9 @@ module.exports = class Server { const { address } = req.body; return WireGuard.updateClientAddress({ clientId, address }); })) + .get('/api/lang', (Util.promisify(async () => { + return LANG; + }))) .listen(PORT, () => { debug(`Listening on http://0.0.0.0:${PORT}`); diff --git a/src/www/index.html b/src/www/index.html index 14259b9e..d54cbe9f 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -33,26 +33,10 @@ d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" /> -
-

- - WireGuard -

-
- - -
-
+

+ + WireGuard +

-
+
alert(err.message || err.toString())) .finally(() => this.refresh().catch(console.error)); }, - changeLang(lang) { - localStorage.setItem('lang', lang); - i18n.locale = lang; - }, }, filters: { bytes, @@ -285,6 +279,12 @@ new Vue({ }, 1000); Promise.resolve().then(async () => { + const lang = await this.api.getLang(); + if (lang !== localStorage.getItem('lang') && i18n.availableLocales.includes(lang)) { + localStorage.setItem('lang', lang); + i18n.locale = lang; + } + const currentRelease = await this.api.getRelease(); const latestRelease = await fetch('https://weejewel.github.io/wg-easy/changelog.json') .then(res => res.json()) diff --git a/src/www/js/i18n.js b/src/www/js/i18n.js index 422d8008..93101a33 100644 --- a/src/www/js/i18n.js +++ b/src/www/js/i18n.js @@ -15,7 +15,7 @@ const messages = { // eslint-disable-line no-unused-vars deleteDialog2: 'This action cannot be undone.', cancel: 'Cancel', create: 'Create', - createdAt: 'Created on ', + createdOn: 'Created on ', lastSeen: 'Last seen on ', totalDownload: 'Total Download: ', totalUpload: 'Total Upload: ', @@ -27,7 +27,6 @@ const messages = { // eslint-disable-line no-unused-vars downloadConfig: 'Download Configuration', madeBy: 'Made by', donate: 'Donate', - changeLang: 'Change language', }, ru: { name: 'Имя', @@ -43,7 +42,7 @@ const messages = { // eslint-disable-line no-unused-vars deleteDialog2: 'Это действие невозможно отменить.', cancel: 'Закрыть', create: 'Создать', - createdAt: 'Создано в ', + createdOn: 'Создано в ', lastSeen: 'Последнее подключение в ', totalDownload: 'Всего скачано: ', totalUpload: 'Всего загружено: ', @@ -55,6 +54,5 @@ const messages = { // eslint-disable-line no-unused-vars downloadConfig: 'Скачать конфигурацию', madeBy: 'Сделано', donate: 'Поблагодарить', - changeLang: 'Выбор языка', }, };