/
arguments.js
76 lines (63 loc) · 1.98 KB
/
arguments.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
const SINGULAR = 'SINGULAR'
const PLURAL = 'PLURAL'
const SINGULAR_CONTEXT = 'SINGULAR_CONTEXT'
const PLURAL_CONTEXT = 'PLURAL_CONTEXT'
const DEFAULTS = {
component: {
name: 'LocalizedString',
singular: 'id',
plural: 'idPlural',
context: 'context',
comment: 'comment',
shortform: 'i18n',
},
function: [
{
type: SINGULAR,
name: '_',
singular: 0,
ignoreError: false,
}, {
type: PLURAL,
name: '_n',
singular: 0,
plural: 1,
ignoreError: false,
}, {
type: SINGULAR_CONTEXT,
name: '_c',
singular: 0,
context: 1,
ignoreError: false,
}, {
type: PLURAL_CONTEXT,
name: '_nc',
singular: 0,
plural: 1,
context: 3,
ignoreError: false,
},
],
}
function getFunctionOptions (state) {
return Object.assign({}, DEFAULTS, state.opts).function
}
function getComponentOptions (state) {
return Object.assign({}, DEFAULTS.component, (state.opts || {}).component)
}
module.exports = {
getSingularFunction: (state, funcName) =>
getFunctionOptions(state).find(func => func.type === SINGULAR && func.name === funcName),
getPluralFunction: (state, funcName) =>
getFunctionOptions(state).find(func => func.type === PLURAL && func.name === funcName),
getSingularContextFunction: (state, funcName) =>
getFunctionOptions(state).find(func => func.type === SINGULAR_CONTEXT && func.name === funcName),
getPluralContextFunction: (state, funcName) =>
getFunctionOptions(state).find(func => func.type === PLURAL_CONTEXT && func.name === funcName),
getComponentName: state => getComponentOptions(state).name,
getSingularAttribute: state => getComponentOptions(state).singular,
getPluralAttribute: state => getComponentOptions(state).plural,
getContextAttribute: state => getComponentOptions(state).context,
getCommentAttribute: state => getComponentOptions(state).comment,
getShortFormAttribute: state => getComponentOptions(state).shortform,
}