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')
|
2018-09-10 00:33:10 +00:00
|
|
|
let localLocales = await WIKI.models.locales.query().select('code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt')
|
2018-04-29 21:55:36 +00:00
|
|
|
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 {
|
2018-05-28 23:36:35 +00:00
|
|
|
locale: WIKI.config.lang.code,
|
|
|
|
autoUpdate: WIKI.config.lang.autoUpdate,
|
|
|
|
namespacing: WIKI.config.lang.namespacing,
|
|
|
|
namespaces: WIKI.config.lang.namespaces
|
2018-05-06 20:19:37 +00:00
|
|
|
}
|
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-28 23:36:35 +00:00
|
|
|
WIKI.config.lang.code = args.locale
|
|
|
|
WIKI.config.lang.autoUpdate = args.autoUpdate
|
|
|
|
WIKI.config.lang.namespacing = args.namespacing
|
|
|
|
WIKI.config.lang.namespaces = args.namespaces
|
|
|
|
await WIKI.configSvc.saveToDb(['lang'])
|
2018-05-06 21:33:41 +00:00
|
|
|
|
|
|
|
await WIKI.lang.setCurrentLocale(args.locale)
|
2018-06-17 21:29:19 +00:00
|
|
|
await WIKI.lang.refreshNamespaces()
|
2018-05-06 21:33:41 +00:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|