+ translations: add twosky integration

This commit is contained in:
Ildar Kamalov
2019-07-18 18:35:23 +03:00
parent a9fbb93f0f
commit 3b0f2e5563
19 changed files with 2283 additions and 2041 deletions

View File

@@ -1,48 +1,41 @@
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const request = require('request-promise');
const LOCALES_DIR = '../../client/src/__locales';
/**
* Hash content
*
* @param {string} content
*/
const hashString = content => crypto.createHash('md5').update(content, 'utf8').digest('hex');
const BASE_FILE = 'en.json';
const LANGUAGE = 'en';
const TWOSKY_URI = process.env.TWOSKY_URI;
const TWOSKY_PROJECT_ID = 'home';
/**
* Prepare post params
*/
const prepare = () => {
let oneskyapp;
try {
oneskyapp = JSON.parse(fs.readFileSync('./oneskyapp.json'));
} catch (err) {
throw new Error(err);
}
const url = `${oneskyapp.url}${oneskyapp.projectId}/files`;
const timestamp = Math.round(new Date().getTime() / 1000);
const getRequestData = (url, projectId) => {
const formData = {
timestamp,
file: fs.createReadStream(path.resolve(LOCALES_DIR, 'en.json')),
file_format: 'HIERARCHICAL_JSON',
locale: 'en',
is_keeping_all_strings: 'false',
api_key: oneskyapp.apiKey,
dev_hash: hashString(timestamp + oneskyapp.secretKey),
format: 'json',
language: LANGUAGE,
filename: BASE_FILE,
project: projectId,
file: fs.createReadStream(path.resolve(LOCALES_DIR, `${LANGUAGE}.json`)),
};
return { url, formData };
return {
url: `${url}/upload`,
formData
};
};
/**
* Make request to onesky to upload new json
* Make request to twosky to upload new json
*/
const upload = () => {
const { url, formData } = prepare();
if (!TWOSKY_URI) {
console.error('No credentials');
return;
}
const { url, formData } = getRequestData(TWOSKY_URI, TWOSKY_PROJECT_ID);
request
.post({ url, formData })
.catch(err => console.log(err));