-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.js
50 lines (41 loc) · 1.13 KB
/
transform.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
'use strict'
const btt = require('browserify-transform-tools')
const common = require('./common')
module.exports = btt.makeRequireTransform('i18nify'
, { evaluateArguments: true
, falafelOptions:
{ ecmaVersion: 6
, allowReturnOutsideFunction: true
}
, jsFilesOnly: true
}
, function(args, opts, done) {
if (args[0] !== 'i18nify')
return done()
if (!args[1]) {
done(null, 'I18NIFY')
return
}
const options = common.readOptions(opts.config)
common.realpath(opts.file, (err, file) => {
if (err) return done(err)
this.emit('i18nify', file, args[1])
const source =
'(' +
options.languages
.filter((lang) => options.default !== lang)
.map((lang) => (
'I18NIFY==' +
JSON.stringify(lang) +
'?require(' +
JSON.stringify(args[1].replace(/%s/, lang)) +
')'
)).join(':') +
':require(' +
JSON.stringify(args[1].replace(/%s/, options.default)) +
'))' +
''
done(null, source)
})
}
)