From c21e3f827ab04f7049e4d15c386fd7c3b9017443 Mon Sep 17 00:00:00 2001 From: dabura667 Date: Sat, 18 Jul 2015 01:12:16 +0900 Subject: [PATCH] Added script for Crowdin automation (incomplete) --- .gitignore | 3 +- Gruntfile.js | 2 +- i18n/crowdin_update.js | 99 ++++++++++++++++++++++++++++++ {cordova => i18n}/docs/appstore_de | 0 {cordova => i18n}/docs/appstore_en | 0 {cordova => i18n}/docs/appstore_es | 0 {cordova => i18n}/docs/appstore_fr | 0 {cordova => i18n}/docs/appstore_ja | 0 {cordova => i18n}/docs/appstore_pt | 0 {po => i18n/po}/de.po | 0 {po => i18n/po}/es.po | 0 {po => i18n/po}/fr.po | 0 {po => i18n/po}/ja.po | 0 {po => i18n/po}/pt.po | 0 {po => i18n/po}/template.pot | 0 package.json | 1 + 16 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 i18n/crowdin_update.js rename {cordova => i18n}/docs/appstore_de (100%) rename {cordova => i18n}/docs/appstore_en (100%) rename {cordova => i18n}/docs/appstore_es (100%) rename {cordova => i18n}/docs/appstore_fr (100%) rename {cordova => i18n}/docs/appstore_ja (100%) rename {cordova => i18n}/docs/appstore_pt (100%) rename {po => i18n/po}/de.po (100%) rename {po => i18n/po}/es.po (100%) rename {po => i18n/po}/fr.po (100%) rename {po => i18n/po}/ja.po (100%) rename {po => i18n/po}/pt.po (100%) rename {po => i18n/po}/template.pot (100%) diff --git a/.gitignore b/.gitignore index f8bacc9bc..762a6d9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # translation -po/*.mo +i18n/po/*.mo +i18n/crowdin_api_key.txt src/js/translations.js # version diff --git a/Gruntfile.js b/Gruntfile.js index faff681d9..23e7a0c60 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -109,7 +109,7 @@ module.exports = function(grunt) { nggettext_extract: { pot: { files: { - 'po/template.pot': [ + 'i18n/po/template.pot': [ 'public/index.html', 'public/views/*.html', 'public/views/**/*.html', diff --git a/i18n/crowdin_update.js b/i18n/crowdin_update.js new file mode 100644 index 000000000..a434460bb --- /dev/null +++ b/i18n/crowdin_update.js @@ -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])); + }; + }); +}); + diff --git a/cordova/docs/appstore_de b/i18n/docs/appstore_de similarity index 100% rename from cordova/docs/appstore_de rename to i18n/docs/appstore_de diff --git a/cordova/docs/appstore_en b/i18n/docs/appstore_en similarity index 100% rename from cordova/docs/appstore_en rename to i18n/docs/appstore_en diff --git a/cordova/docs/appstore_es b/i18n/docs/appstore_es similarity index 100% rename from cordova/docs/appstore_es rename to i18n/docs/appstore_es diff --git a/cordova/docs/appstore_fr b/i18n/docs/appstore_fr similarity index 100% rename from cordova/docs/appstore_fr rename to i18n/docs/appstore_fr diff --git a/cordova/docs/appstore_ja b/i18n/docs/appstore_ja similarity index 100% rename from cordova/docs/appstore_ja rename to i18n/docs/appstore_ja diff --git a/cordova/docs/appstore_pt b/i18n/docs/appstore_pt similarity index 100% rename from cordova/docs/appstore_pt rename to i18n/docs/appstore_pt diff --git a/po/de.po b/i18n/po/de.po similarity index 100% rename from po/de.po rename to i18n/po/de.po diff --git a/po/es.po b/i18n/po/es.po similarity index 100% rename from po/es.po rename to i18n/po/es.po diff --git a/po/fr.po b/i18n/po/fr.po similarity index 100% rename from po/fr.po rename to i18n/po/fr.po diff --git a/po/ja.po b/i18n/po/ja.po similarity index 100% rename from po/ja.po rename to i18n/po/ja.po diff --git a/po/pt.po b/i18n/po/pt.po similarity index 100% rename from po/pt.po rename to i18n/po/pt.po diff --git a/po/template.pot b/i18n/po/template.pot similarity index 100% rename from po/template.pot rename to i18n/po/template.pot diff --git a/package.json b/package.json index 56cd14751..5509a6c4c 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "test": "./node_modules/.bin/grunt test-coveralls" }, "devDependencies": { + "adm-zip": "git://github.com/cthackers/adm-zip.git", "angular": "^1.3.14", "angular-mocks": "^1.3.14", "grunt-contrib-compress": "^0.13.0",