Last active
August 29, 2015 14:24
-
-
Save karl-gustav/ba2074c21393439c68d6 to your computer and use it in GitHub Desktop.
class for working with zanata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var request = require('request'), | |
toFile = require('vinyl-source-stream'), | |
toBuffer = require('vinyl-buffer'), | |
mergeStream = require('merge2'), | |
ZANATA_USER = { | |
USERNAME: '<place username here>', | |
TOKEN: '<place token here>' | |
}; | |
module.exports = { | |
downloadPoTranslationFiles : downloadPoTranslationFiles, | |
downloadVinylFileFromZanata: downloadVinylFileFromZanata, | |
downloadFromZanata: downloadFromZanata | |
}; | |
function downloadPoTranslationFiles (languageCodes, projectName, version, documentName) { | |
var translations = languageCodes.map(function (lang) { | |
return { | |
path: lang + '.po', | |
url: 'http://translations.fronter.net/zanata/rest/file/translation/' + | |
projectName +'/' + | |
version + '/' + | |
lang + '/po?docId=' + | |
documentName | |
}; | |
}); | |
return mergeStream( | |
translations.map(function (translation) { | |
return downloadVinylFileFromZanata(translation.url, translation.path) | |
}) | |
); | |
} | |
function downloadVinylFileFromZanata (fileUrl, filePath) { | |
return downloadFromZanata(fileUrl) | |
.pipe(toFile(filePath)) | |
.pipe(toBuffer()); | |
} | |
function downloadFromZanata (url) { | |
return request.get({ | |
url: url, | |
headers: { | |
'X-Auth-User': ZANATA_USER.USERNAME, | |
'X-Auth-Token': ZANATA_USER.TOKEN | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment