-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
30 lines (25 loc) · 925 Bytes
/
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
var gutil = require('gulp-util')
var yml = require('js-yaml')
var request = require('request')
function string_src (filename, string) {
var src = require('stream').Readable({ objectMode: true })
src._read = function () {
this.push(new gutil.File({ cwd: '', base: '', path: filename, contents: new Buffer(string) }))
this.push(null)
}
return src
}
function downloadLocales (options) {
if (!options || !options.apiKey) throw new Error('options.apiKey is required')
var stream = require('merge-stream')()
request(`https://api.localeapp.com/v1/projects/${options.apiKey}/translations/all.yml`, function (err, raw, body) {
if (err) throw err
var languages = yml.load(body)
Object.keys(languages).map(function (key) {
var string = JSON.stringify(languages[key], null, 2)
stream.add(string_src(`${key}.json`, string))
})
})
return stream
}
module.exports = downloadLocales