mirror of
https://github.com/WebTools-NG/WebTools-NG
synced 2024-11-26 21:10:19 +00:00
#77 fixed
This commit is contained in:
parent
a3cced6289
commit
5e59562400
6 changed files with 57 additions and 46 deletions
|
@ -17,15 +17,14 @@
|
|||
|
||||
<script>
|
||||
// User Config
|
||||
import {wtconfig} from '../wtutils';
|
||||
import i18n from '../i18n';
|
||||
const log = require('electron-log');
|
||||
|
||||
export default {
|
||||
name: 'locale-changer',
|
||||
data () {
|
||||
return {
|
||||
olLangs: [],
|
||||
selectedLang: wtconfig.get('General.language')
|
||||
olLangs: []
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -33,8 +32,8 @@ export default {
|
|||
this.getOnlineLangs();
|
||||
},
|
||||
methods: {
|
||||
forcedownload() {
|
||||
this.$store.dispatch("forceDownload", { "langCode": this.selectedLang});
|
||||
forcedownload() {
|
||||
this.$store.dispatch("updateAndSetLang", { "langCode": i18n.locale, "forceDownload": true});
|
||||
},
|
||||
getOnlineLangs() {
|
||||
var onlineLangs = this.$store.getters.getLanguages
|
||||
|
@ -46,9 +45,8 @@ export default {
|
|||
this.olLangs.push(entry)
|
||||
}
|
||||
},
|
||||
onChange(event) {
|
||||
log.info('language set to:' + event.target.value);
|
||||
wtconfig.set('General.language', event.target.value);
|
||||
onChange(event) {
|
||||
this.$store.dispatch('updateAndSetLang', { "langCode": event.target.value, "forceDownload": false});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
31
src/i18n.js
31
src/i18n.js
|
@ -1,28 +1,31 @@
|
|||
import Vue from 'vue'
|
||||
import VueI18n from 'vue-i18n'
|
||||
import {wtutils} from './wtutils'
|
||||
import {wtutils, wtconfig} from './wtutils'
|
||||
|
||||
const log = require('electron-log');
|
||||
console.log = log.log;
|
||||
|
||||
Vue.use(VueI18n)
|
||||
|
||||
function loadLocaleMessages () {
|
||||
wtutils.MoveToHome();
|
||||
var fs = require('fs');
|
||||
wtutils.MoveToHome();
|
||||
const messages = {}
|
||||
const items = wtutils.LangFiles
|
||||
const localHome = wtutils.Home + '/locales'
|
||||
log.verbose(`Files count is: ${items.length}`)
|
||||
for (var i=0; i<items.length; i++) {
|
||||
log.verbose(`found translation file : ${items[i]}`);
|
||||
let langCode = items[i].split(".")[0];
|
||||
let langFile = localHome + '/' + items[i];
|
||||
messages[langCode] = JSON.parse(fs.readFileSync(langFile, 'utf8'));
|
||||
}
|
||||
log.verbose(`********* Done reading translations ***********`)
|
||||
const fs = require('fs')
|
||||
// Force read en lang, since it's the fallback
|
||||
const langCode = 'en'
|
||||
var langFile = wtutils.Home + '/locales/' + langCode + '.json'
|
||||
log.debug(`Loading language: ${langCode}`)
|
||||
messages[langCode] = JSON.parse(fs.readFileSync(langFile, 'utf8'));
|
||||
if (wtconfig.get('General.language') != 'en'){
|
||||
// We need to preload an additional language
|
||||
const langCode = wtconfig.get('General.language')
|
||||
langFile = wtutils.Home + '/locales/' + langCode + '.json'
|
||||
log.debug(`Loading language: ${langCode}`)
|
||||
messages[langCode] = JSON.parse(fs.readFileSync(langFile, 'utf8'));
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
|
||||
export default new VueI18n({
|
||||
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
|
||||
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
|
||||
|
|
|
@ -70,6 +70,6 @@ import 'bootstrap-vue/dist/bootstrap-vue.css'
|
|||
new Vue({
|
||||
render: h => h(App),
|
||||
router: router,
|
||||
i18n,
|
||||
store: store
|
||||
store: store,
|
||||
i18n
|
||||
}).$mount('#app')
|
||||
|
|
|
@ -6,7 +6,7 @@ import { wtutils} from './wtutils';
|
|||
const menuTemplate = [
|
||||
{
|
||||
// File menu
|
||||
label: i18n.t("Common.Menu.File.menuFile"),
|
||||
label: i18n.t("Common.Menu.File.menuFile"),
|
||||
submenu:
|
||||
[
|
||||
wtutils.isMac ?
|
||||
|
|
|
@ -1,19 +1,38 @@
|
|||
// mutation.js
|
||||
//import {App} from '../../main'
|
||||
|
||||
import i18n from '../../i18n'
|
||||
import {wtutils, wtconfig} from '../../wtutils'
|
||||
import VueI18n from 'vue-i18n';
|
||||
const log = require('electron-log');
|
||||
console.log = log.log;
|
||||
|
||||
export const mutations = {
|
||||
SET_LANG (state, payload) {
|
||||
//App.$i18n.locale = payload
|
||||
i18n.locale = payload
|
||||
SET_LANG (state, payload) {
|
||||
log.info(`Set language to: ${payload}`)
|
||||
VueI18n.locale = payload
|
||||
wtconfig.set('General.language', payload)
|
||||
}
|
||||
}
|
||||
export const actions = {
|
||||
setLang({commit}, payload) {
|
||||
log.info(`Set lang to: ${JSON.stringify(payload)}`)
|
||||
commit('SET_LANG', payload)
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
async updateAndSetLang({commit}, { langCode, forceDownload }){
|
||||
const fs = require('fs')
|
||||
try {
|
||||
log.info(`Loading lang: ${JSON.stringify(langCode)}`)
|
||||
var langFile = wtutils.Home + '/locales/' + langCode + '.json'
|
||||
if (!fs.existsSync(langFile) | forceDownload) {
|
||||
// Do something
|
||||
log.debug(`Need to download language file for: ${langCode}`)
|
||||
await this.dispatch("forceDownload", { "langCode": langCode});
|
||||
}
|
||||
const res = await JSON.parse(fs.readFileSync(langFile, 'utf8'));
|
||||
i18n.setLocaleMessage(langCode, res)
|
||||
commit('SET_LANG', langCode)
|
||||
}
|
||||
catch(e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const serverModule = {
|
||||
|
|
|
@ -66,30 +66,21 @@ const actions = {
|
|||
const wtutils = require('../../wtutils');
|
||||
const Path = require('path')
|
||||
const path = Path.resolve(wtutils.wtutils.Home, 'locales', langCode + '.json')
|
||||
|
||||
const config = {
|
||||
headers: headers
|
||||
}
|
||||
requestBody['language'] = langCode;
|
||||
requestBody['type'] = 'key_value_json';
|
||||
|
||||
requestBody['type'] = 'key_value_json';
|
||||
const response = await axios.post(baseUrl + 'projects/export', qs.stringify(requestBody), config)
|
||||
const link = await response.data.result.url;
|
||||
console.log('Ged link: ' + link)
|
||||
|
||||
const link = await response.data.result.url;
|
||||
// axios image download with response type "stream"
|
||||
const dwnlresp = await axios({
|
||||
method: 'GET',
|
||||
url: link,
|
||||
responseType: 'stream'
|
||||
})
|
||||
|
||||
var json = JSON.stringify(dwnlresp.data);
|
||||
fs.writeFile(path, json, function(err) {
|
||||
if (err) throw err;
|
||||
console.log('complete');
|
||||
});
|
||||
|
||||
fs.writeFileSync(path, json);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue