2018-04-29 21:55:36 +00:00
|
|
|
const graphHelper = require('../../helpers/graph')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Query: {
|
|
|
|
async localization() { return {} }
|
|
|
|
},
|
|
|
|
Mutation: {
|
|
|
|
async localization() { return {} }
|
|
|
|
},
|
|
|
|
LocalizationQuery: {
|
|
|
|
async locales(obj, args, context, info) {
|
|
|
|
let remoteLocales = await WIKI.redis.get('locales')
|
|
|
|
let localLocales = await WIKI.db.Locale.findAll({
|
|
|
|
attributes: {
|
|
|
|
exclude: ['strings']
|
|
|
|
},
|
|
|
|
raw: true
|
|
|
|
})
|
|
|
|
remoteLocales = (remoteLocales) ? JSON.parse(remoteLocales) : localLocales
|
|
|
|
return _.map(remoteLocales, rl => {
|
|
|
|
let isInstalled = _.some(localLocales, ['code', rl.code])
|
|
|
|
return {
|
|
|
|
...rl,
|
|
|
|
isInstalled,
|
|
|
|
installDate: isInstalled ? _.find(localLocales, ['code', rl.code]).updatedAt : null
|
|
|
|
}
|
|
|
|
})
|
2018-05-06 20:19:37 +00:00
|
|
|
},
|
|
|
|
async config(obj, args, context, info) {
|
|
|
|
return {
|
|
|
|
locale: WIKI.config.site.lang,
|
|
|
|
autoUpdate: WIKI.config.site.langAutoUpdate
|
|
|
|
}
|
2018-04-29 21:55:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
LocalizationMutation: {
|
2018-05-07 03:21:48 +00:00
|
|
|
async downloadLocale(obj, args, context) {
|
|
|
|
try {
|
|
|
|
const job = await WIKI.queue.job.fetchGraphLocale.add({
|
|
|
|
locale: args.locale
|
|
|
|
}, {
|
|
|
|
timeout: 30000
|
|
|
|
})
|
|
|
|
await job.finished()
|
|
|
|
return {
|
|
|
|
responseResult: graphHelper.generateSuccess('Locale downloaded successfully')
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return graphHelper.generateError(err)
|
|
|
|
}
|
|
|
|
},
|
2018-04-29 21:55:36 +00:00
|
|
|
async updateLocale(obj, args, context) {
|
|
|
|
try {
|
2018-05-06 21:33:41 +00:00
|
|
|
WIKI.config.site.lang = args.locale
|
|
|
|
WIKI.config.site.langAutoUpdate = args.autoUpdate
|
|
|
|
await WIKI.configSvc.saveToDb(['site'])
|
|
|
|
|
|
|
|
await WIKI.lang.setCurrentLocale(args.locale)
|
|
|
|
|
2018-04-29 21:55:36 +00:00
|
|
|
return {
|
2018-05-07 03:21:48 +00:00
|
|
|
responseResult: graphHelper.generateSuccess('Locale config updated')
|
2018-04-29 21:55:36 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return graphHelper.generateError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|