-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (70 loc) · 1.86 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fields = require('./fields');
const queries = require('./queries');
const methods = require('./methods');
const handlers = require('./handlers');
module.exports = {
extend: '@apostrophecms/piece-type',
options: {
label: 'aposI18nStatic:label',
pluralLabel: 'aposI18nStatic:pluralLabel',
i18n: {
ns: 'aposI18nStatic',
browser: true
},
seoFields: false,
openGraph: false,
editRole: 'admin',
publishRole: 'admin',
excludeNamespaces: [],
autopublish: true,
quickCreate: false,
showCreate: false,
// Don't pollute project level slug namespace
slugPrefix: 'i18n-static-'
},
filters: {
add: {
namespace: {
label: 'aposI18nStatic:namespace',
def: null
}
}
},
columns: {
add: {
namespace: {
label: 'aposI18nStatic:namespace'
},
valueSingular: {
label: 'aposI18nStatic:valueSingular'
},
valuePlural: {
label: 'aposI18nStatic:valuePlural'
}
}
},
middleware(self) {
return {
async updateI18Next(req, res, next) {
const aposLocale = `${req.locale}:${req.mode}`;
self.i18nStaticIds = self.i18nStaticIds || {};
if (self.i18nStaticIds[aposLocale] !== req.data.global.i18nStaticId) {
const namespaces =
(await self.apos.cache.get(req.locale, 'i18n-static')) ||
(await self.findPiecesAndGroupByNamespace(aposLocale));
for (const namespace of namespaces) {
const ns = namespace._id;
const resources = self.formatPieces(namespace.pieces);
self.apos.i18n.i18next.addResourceBundle(req.locale, ns, resources, true, true);
}
}
self.i18nStaticIds[aposLocale] = req.data.global.i18nStaticId;
return next();
}
};
},
fields,
queries,
methods,
handlers
};