-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
46 lines (38 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const path = require('path')
const library = require('./library')
const defaults = {
provider: 'google-sheet',
languages: ['en'],
fallbackLocale: 'en',
outputFilePrefix: 'locale',
maxAge: 1000 * 60 * 60,
localeNamespaceStore: 'i18n',
staticFolder: 'i18n'
}
async function importI18n({ conf, log, error }) {
return library.importI18n({
path: conf.path,
conf,
log,
error
})
}
module.exports = async function nuxtDynamicI18n(_moduleOptions) {
// Set default translate path into static directory
defaults.path = path.join(this.nuxt.options.srcDir, this.nuxt.options.dir.static, defaults.staticFolder)
// Get options from module injection
const conf = Object.assign(defaults, this.options.dynamicI18n, _moduleOptions)
const importOptions = {
conf,
log: console.log,
error: console.error
}
// Load translates from provider
await importI18n(importOptions)
this.addPlugin({
src: path.resolve(__dirname, 'plugin.js'),
options: conf
})
if (conf.maxAge) setInterval(() => importI18n(importOptions), conf.maxAge)
}
module.exports.meta = require('./package.json')