-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
125 lines (114 loc) · 3.54 KB
/
test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require('should')
var translate = require('./index')
var describe = global.describe
var it = global.it
var localesJA = require('./locales/ja.json')
var localesEN = require('./locales/en.json')
var localesZH = require('./locales/zh.json')
var localesZH_TW = require('./locales/zh_tw.json')
var localesKO = require('./locales/ko.json')
describe('test tb-i18n-loader', function () {
it('translate keys', function () {
var query = '?languages[]=en'
var contextTranslate = translate.bind({query: query})
var desciption = `
{
"FRI": "FRI",
"MON": "MON",
"key1": "key1"
}
`
var expects = [
'var i18n = require(\'tb-i18n\');',
'i18n.setLocales(\'en\', {',
` "FRI": "${localesEN['FRI'] || ''}",`,
` "MON": "${localesEN['MON'] || ''}",`,
` "key1": "${localesEN['key1'] || ''}"`,
'});',
'module.exports = i18n;'
]
contextTranslate(desciption).should.eql(expects.join('\n'))
})
it('default languages', function () {
var query = ''
var contextTranslate = translate.bind({query: query})
var desciption = `
{
"FRI": "FRI",
"MON": "MON",
"key1": "key1"
}
`
var expects = [
'var i18n = require(\'tb-i18n\');',
'i18n.setLocales(\'zh\', {',
` "FRI": "${localesZH['FRI'] || ''}",`,
` "MON": "${localesZH['MON'] || ''}",`,
` "key1": "${localesZH['key1'] || ''}"`,
'});',
'i18n.setLocales(\'zh_tw\', {',
` "FRI": "${localesZH_TW['FRI'] || ''}",`,
` "MON": "${localesZH_TW['MON'] || ''}",`,
` "key1": "${localesZH_TW['key1'] || ''}"`,
'});',
'i18n.setLocales(\'en\', {',
` "FRI": "${localesEN['FRI'] || ''}",`,
` "MON": "${localesEN['MON'] || ''}",`,
` "key1": "${localesEN['key1'] || ''}"`,
'});',
'i18n.setLocales(\'ja\', {',
` "FRI": "${localesJA['FRI'] || ''}",`,
` "MON": "${localesJA['MON'] || ''}",`,
` "key1": "${localesJA['key1'] || ''}"`,
'});',
'i18n.setLocales(\'ko\', {',
` "FRI": "${localesKO['FRI'] || ''}",`,
` "MON": "${localesKO['MON'] || ''}",`,
` "key1": "${localesKO['key1'] || ''}"`,
'});',
'module.exports = i18n;'
]
contextTranslate(desciption).should.eql(expects.join('\n'))
})
it('with namespace', function () {
var query = '?languages[]=en'
var contextTranslate = translate.bind({query: query})
var desciption = `
@namespace: all.
{
"member": "member",
"project": "project",
"key1": "key1"
}
`
var expects = [
'var i18n = require(\'tb-i18n\');',
'i18n.setLocales(\'en\', {',
` "all.member": "${localesEN['all.member'] || ''}",`,
` "all.project": "${localesEN['all.project'] || ''}",`,
` "all.key1": "${localesEN['all.key1'] || ''}"`,
'});',
'module.exports = i18n;'
]
contextTranslate(desciption).should.eql(expects.join('\n'))
})
it('desciption as', function () {
var query = '?languages[]=en&&descriptionAs=en'
var contextTranslate = translate.bind({query: query})
var desciption = {
'FRI': 'desciption FRI',
'MON': 'desciption MON',
'key1': 'desciption key1'
}
var expects = [
'var i18n = require(\'tb-i18n\');',
'i18n.setLocales(\'en\', {',
` "FRI": "${desciption['FRI']}",`,
` "MON": "${desciption['MON']}",`,
` "key1": "${desciption['key1']}"`,
'});',
'module.exports = i18n;'
]
contextTranslate(JSON.stringify(desciption)).should.eql(expects.join('\n'))
})
})