add environment variable for changes lang

This commit is contained in:
cany748 2022-06-20 20:09:17 +07:00
parent f8c414042a
commit 2c29909ef6
6 changed files with 25 additions and 31 deletions

View file

@ -117,4 +117,11 @@ class API {
});
}
async getLang() {
return this.call({
method: 'get',
path: '/lang',
});
}
}

View file

@ -55,8 +55,6 @@ new Vue({
currentRelease: null,
latestRelease: null,
langDropdownShow: false,
chartOptions: {
chart: {
background: 'transparent',
@ -255,10 +253,6 @@ new Vue({
.catch(err => 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())

View file

@ -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: 'Выбор языка',
},
};