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) {
|
2019-02-13 22:20:46 +00:00
|
|
|
let remoteLocales = await WIKI.cache.get('locales')
|
2018-09-10 00:33:10 +00:00
|
|
|
let localLocales = await WIKI.models.locales.query().select('code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt')
|
2019-06-01 00:43:29 +00:00
|
|
|
remoteLocales = remoteLocales || localLocales
|
2018-04-29 21:55:36 +00:00
|
|
|
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
|
|
|
}
|
2019-01-12 23:33:30 +00:00
|
|
|
},
|
|
|
|
translations (obj, args, context, info) {
|
|
|
|
return WIKI.lang.getByNamespace(args.locale, args.namespace)
|
2018-04-29 21:55:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
LocalizationMutation: {
|
2018-05-07 03:21:48 +00:00
|
|
|
async downloadLocale(obj, args, context) {
|
|
|
|
try {
|
2019-02-13 22:20:46 +00:00
|
|
|
const job = await WIKI.scheduler.registerJob({
|
|
|
|
name: 'fetch-graph-locale',
|
|
|
|
immediate: true
|
|
|
|
}, args.locale)
|
|
|
|
await job.finished
|
2018-05-07 03:21:48 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|