|
@@ -5,6 +5,8 @@ const { createApolloFetch } = require('apollo-fetch')
|
|
|
/* global WIKI */
|
|
|
|
|
|
WIKI.redis = require('../core/redis').init()
|
|
|
+WIKI.db = require('../core/db').init()
|
|
|
+
|
|
|
const apollo = createApolloFetch({
|
|
|
uri: 'https://graph.requarks.io'
|
|
|
})
|
|
@@ -13,7 +15,11 @@ module.exports = async (job) => {
|
|
|
WIKI.logger.info('Syncing locales with Graph endpoint...')
|
|
|
|
|
|
try {
|
|
|
- const resp = await apollo({
|
|
|
+ await WIKI.configSvc.loadFromDb(['site'])
|
|
|
+
|
|
|
+ // -> Fetch locales list
|
|
|
+
|
|
|
+ const respList = await apollo({
|
|
|
query: `{
|
|
|
localization {
|
|
|
locales {
|
|
@@ -27,8 +33,38 @@ module.exports = async (job) => {
|
|
|
}
|
|
|
}`
|
|
|
})
|
|
|
- const locales = _.sortBy(_.get(resp, 'data.localization.locales', []), 'name').map(lc => ({...lc, isInstalled: (lc.code === 'en')}))
|
|
|
+ const locales = _.sortBy(_.get(respList, 'data.localization.locales', []), 'name').map(lc => ({...lc, isInstalled: (lc.code === 'en')}))
|
|
|
WIKI.redis.set('locales', JSON.stringify(locales))
|
|
|
+ const currentLocale = _.find(locales, ['code', WIKI.config.site.lang])
|
|
|
+
|
|
|
+ // -> Download locale strings
|
|
|
+
|
|
|
+ if (WIKI.config.site.langAutoUpdate) {
|
|
|
+ const respStrings = await apollo({
|
|
|
+ query: `{
|
|
|
+ localization {
|
|
|
+ strings(code: "${WIKI.config.site.lang}") {
|
|
|
+ key
|
|
|
+ value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ })
|
|
|
+ const strings = _.get(respStrings, 'data.localization.strings', [])
|
|
|
+ let lcObj = {}
|
|
|
+ _.forEach(strings, row => {
|
|
|
+ if (_.includes(row.key, '::')) { return }
|
|
|
+ _.set(lcObj, row.key.replace(':', '.'), row.value)
|
|
|
+ })
|
|
|
+
|
|
|
+ WIKI.db.Locale.upsert({
|
|
|
+ code: WIKI.config.site.lang,
|
|
|
+ strings: lcObj,
|
|
|
+ isRTL: currentLocale.isRTL,
|
|
|
+ name: currentLocale.name,
|
|
|
+ nativeName: currentLocale.nativeName
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
WIKI.logger.info('Syncing locales with Graph endpoint: [ COMPLETED ]')
|
|
|
} catch (err) {
|