forked from kiuKisas/elderjs-plugin-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (40 loc) · 1.15 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
const { defaultHooks, getOptionalHooks } = require('./hooks')
const plugin = {
name: 'elderjs-plugin-i18n',
description: 'i18n support for elderjs',
init: (plugin) => {
plugin.config.enableExcludeLocales = plugin.config.locales.excludes.length > 0
plugin.hooks = [plugin.hooks, getOptionalHooks(plugin.config)].flat()
plugin.config.locales.all = plugin.config.locales.all.map((locale) =>
typeof locale === 'string' ? { code: locale, iso: locale } : locale
)
const locales = plugin.config.locales.all.map((locale) => locale.code)
const dictionaryTemplate = locales.reduce((o, key) => ({ ...o, [key]: {} }), {})
return Object.assign(plugin, {
locales,
dictionaries: {
requests: dictionaryTemplate,
locales: Object.assign({}, dictionaryTemplate),
data: Object.assign({}, dictionaryTemplate)
}
})
},
hooks: defaultHooks,
config: {
locales: {
default: 'en',
all: ['en'],
excludes: []
},
permalink: {
prefix: true,
prefixDefault: true,
lastSlash: true
},
seo: {
hreflang: true,
lang: true
}
}
}
module.exports = plugin