Added script for Crowdin automation (incomplete)
This commit is contained in:
parent
e4b69181e2
commit
c21e3f827a
16 changed files with 103 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
# translation
|
# translation
|
||||||
po/*.mo
|
i18n/po/*.mo
|
||||||
|
i18n/crowdin_api_key.txt
|
||||||
src/js/translations.js
|
src/js/translations.js
|
||||||
|
|
||||||
# version
|
# version
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ module.exports = function(grunt) {
|
||||||
nggettext_extract: {
|
nggettext_extract: {
|
||||||
pot: {
|
pot: {
|
||||||
files: {
|
files: {
|
||||||
'po/template.pot': [
|
'i18n/po/template.pot': [
|
||||||
'public/index.html',
|
'public/index.html',
|
||||||
'public/views/*.html',
|
'public/views/*.html',
|
||||||
'public/views/**/*.html',
|
'public/views/**/*.html',
|
||||||
|
|
|
||||||
99
i18n/crowdin_update.js
Normal file
99
i18n/crowdin_update.js
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var fs = require('fs')
|
||||||
|
var querystring = require('querystring');
|
||||||
|
var http = require('http');
|
||||||
|
var AdmZip = require('adm-zip');
|
||||||
|
|
||||||
|
var crowdin_identifier = 'copay'
|
||||||
|
|
||||||
|
var crowdin_file_name1 = 'template.pot'
|
||||||
|
var local_file_name1 = './po/template.pot'
|
||||||
|
|
||||||
|
var crowdin_file_name2 = 'template.pot'
|
||||||
|
var local_file_name2 = './docs/appstore_en'
|
||||||
|
|
||||||
|
// obtain the crowdin api key
|
||||||
|
var crowdin_api_key = '';
|
||||||
|
fs.readFile('./crowdin_api_key.txt', 'utf8', function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
crowdin_api_key = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (crowdin_api_key != '') {
|
||||||
|
var host_url = 'http://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key;
|
||||||
|
|
||||||
|
var post_data = querystring.stringify({
|
||||||
|
'files[' + crowdin_file_name1 + ']' : '@' + local_file_name1,
|
||||||
|
'files[' + crowdin_file_name2 + ']' : '@' + local_file_name2
|
||||||
|
});
|
||||||
|
|
||||||
|
var post_options = {
|
||||||
|
host: host_url,
|
||||||
|
port: '80',
|
||||||
|
path: '',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
'Content-Length': post_data.length
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var post_req = http.request(post_options, function(res) {
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', function (chunk) {
|
||||||
|
console.log('Response: ' + chunk);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
post_req.on('error', function(e) {
|
||||||
|
console.log('problem with request: ' + e.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
post_req.write(post_data);
|
||||||
|
|
||||||
|
// This post updates the english files on crowdin.
|
||||||
|
// https://crowdin.com/page/api/update-file
|
||||||
|
post_req.end();
|
||||||
|
|
||||||
|
// This call will tell the server to generate a new zip file for you based on most recent translations.
|
||||||
|
http.get('http://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key, function(res) {
|
||||||
|
console.log("Got response: " + res.statusCode);
|
||||||
|
}).on('error', function(e) {
|
||||||
|
console.log("Got error: " + e.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Download most recent translations for all languages.
|
||||||
|
http.get('http://crowdin.com/download/project/' + crowdin_identifier + '.zip', function(res) {
|
||||||
|
var data = [], dataLen = 0;
|
||||||
|
|
||||||
|
res.on('data', function(chunk) {
|
||||||
|
data.push(chunk);
|
||||||
|
dataLen += chunk.length;
|
||||||
|
}).on('end', function() {
|
||||||
|
var buf = new Buffer(dataLen);
|
||||||
|
for (var i=0, len = data.length, pos = 0; i < len; i++) {
|
||||||
|
data[i].copy(buf, pos);
|
||||||
|
pos += data[i].length;
|
||||||
|
}
|
||||||
|
var zip = new AdmZip(buf);
|
||||||
|
var zipEntries = zip.getEntries();
|
||||||
|
console.log(zipEntries.length)
|
||||||
|
for (var i = 0; i < zipEntries.length; i++) {
|
||||||
|
// parse each file from the zip, ex. http://crowdin.com/download/project/electrum.zip
|
||||||
|
// the filename for each file is the same, but they are separated into locale folder names.
|
||||||
|
// those foldernames might be able to be used to automatically rename each file to 'locale.po' like current.
|
||||||
|
|
||||||
|
console.log(zip.readAsText(zipEntries[i]));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
"test": "./node_modules/.bin/grunt test-coveralls"
|
"test": "./node_modules/.bin/grunt test-coveralls"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"adm-zip": "git://github.com/cthackers/adm-zip.git",
|
||||||
"angular": "^1.3.14",
|
"angular": "^1.3.14",
|
||||||
"angular-mocks": "^1.3.14",
|
"angular-mocks": "^1.3.14",
|
||||||
"grunt-contrib-compress": "^0.13.0",
|
"grunt-contrib-compress": "^0.13.0",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue