-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
71 lines (57 loc) · 1.59 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
var test = require('tape')
var os = require('os')
var fs = require('fs')
var i18nify = require('./')
function makeDict (lang, data) {
data[''] = {
domain: 'messages',
lang: lang,
plural_forms: 'nplurals=2; plural=(n != 1);'
}
var path = os.tmpdir() + '/i18nify-dict-' + Date.now()
fs.mkdirSync(path); fs.mkdirSync(path + '/' + lang)
fs.writeFileSync(path + '/' + lang + '/dict.json', JSON.stringify({messages: data}))
return path
}
test('Should translate text', function (t) {
t.plan(1)
var lang = 'es-ES'
var translations = {
'Enter the serial number': [
'Introduzca número de serie'
]
}
var path = makeDict(lang, translations)
var tr = i18nify('test.hbs', {lang: lang, path: path})
var out = ''
tr.on('data', function (data) {
out += data
})
tr.on('end', function () {
t.equal(out, '<label data-i18n="test.hbs">Introduzca número de serie</label>')
t.end()
})
tr.write('<label data-i18n>Enter the serial number</label>')
tr.end()
})
test('Should translate attributes', function (t) {
t.plan(1)
var lang = 'es-ES'
var translations = {
'Enter the serial number': [
'Introduzca número de serie'
]
}
var path = makeDict(lang, translations)
var tr = i18nify('test.hbs', {lang: lang, path: path})
var out = ''
tr.on('data', function (data) {
out += data
})
tr.on('end', function () {
t.equal(out, '<input type="text" placeholder="Introduzca número de serie">')
t.end()
})
tr.write('<input type="text" placeholder="Enter the serial number" data-i18n-attr="placeholder">')
tr.end()
})