Socket
Socket
Sign inDemoInstall

crowdin-cli

Package Overview
Dependencies
63
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.3.0

256

api.js

@@ -1,6 +0,9 @@

/*jslint node: true*/
/*jslint node: true, nomen: true*/
'use strict';
var https = require('https'),
fs = require('fs'),
querystring = require('querystring'),
request = require('request'),
extend = require('util')._extend,
apiKey,

@@ -18,3 +21,4 @@ baseUrl = 'https://api.crowdin.com',

validateKey();
var url = baseUrl + '/api/' + apiUrl + '?json=true&key=' + apiKey;
var url = baseUrl + '/api/' + apiUrl,
params = { json: true, key: apiKey };
if (verbose > 0) {

@@ -25,7 +29,13 @@ console.log("Doing GET request:");

return request.get(url, function (error, response, body) {
if (!error && response.statusCode === 200) {
callback(null, JSON.parse(body));
return request.get({ url: url, qs: params }, function (error, response, body) {
if (callback) {
if (!error && response.statusCode === 200) {
callback(null, JSON.parse(body));
} else {
callback(error);
}
} else {
callback(error);
if (error) {
throw error;
}
}

@@ -35,5 +45,11 @@ });

function postApiCall(apiUrl, callback) {
function postApiCall(apiUrl, getOptions, callback) {
validateKey();
var url = baseUrl + '/api/' + apiUrl + '?json=true&key=' + apiKey;
if (callback === undefined) {
callback = getOptions;
getOptions = {};
}
var url = baseUrl + '/api/' + apiUrl,
params = extend(getOptions, { json: true, key: apiKey });
if (verbose > 0) {

@@ -44,7 +60,13 @@ console.log("Doing POST request:");

return request.post(url, function (error, response, body) {
if (!error && response.statusCode === 200) {
callback(null, JSON.parse(body));
return request.post({ url: url, qs: params }, function (error, response, body) {
if (callback) {
if (!error && response.statusCode === 200) {
callback(null, JSON.parse(body));
} else {
callback(error);
}
} else {
callback(error);
if (error) {
throw error;
}
}

@@ -54,2 +76,32 @@ });

function postApiCallWithFormData(apiUrl, getOptions, postOptions, callback) {
validateKey();
if (callback === undefined) {
callback = postOptions;
postOptions = getOptions;
getOptions = {};
}
var url = baseUrl + '/api/' + apiUrl,
params = extend(getOptions, { json: true, key: apiKey });
if (verbose > 0) {
console.log("Doing POST request:");
console.log(url);
}
return request.post({ url: url, qs: params, formData: postOptions || {} }, function (error, response, body) {
if (callback) {
if (!error && response.statusCode === 200) {
callback(null, JSON.parse(body));
} else {
callback(error);
}
} else {
if (error) {
throw error;
}
}
});
}
function getApiRequest(apiUrl, callback) {

@@ -76,5 +128,97 @@ validateKey();

},
/**
* Add new file to Crowdin project
* @param projectName {String} Should contain the project identifier
* @param files {Array} Files array that should be added to Crowdin project.
* Array keys should contain file names with path in Crowdin project.
* Note! 20 files max are allowed to upload per one time file transfer.
* @param params {Object} Information about uploaded files.
* @param callback {Function} Callback to call on function completition.
*/
addFile: function (projectName, files, params, callback) {
if (callback === undefined) {
callback = params;
params = {};
}
var filesInformation = {};
files.forEach(function (fileName) {
var index = "files[" + fileName + "]";
filesInformation[index] = fs.createReadStream(fileName);
});
return postApiCallWithFormData('project/' + projectName + '/add-file', extend(filesInformation, params), callback);
},
/**
* Upload latest version of your localization file to Crowdin.
* @param projectName {String} Should contain the project identifier
* @param files {Array} Files array that should be updated.
* Note! 20 files max are allowed to upload per one time file transfer.
* @param params {Object} Information about updated files.
* @param callback {Function} Callback to call on function completition.
*/
updateFile: function (projectName, files, params, callback) {
if (callback === undefined) {
callback = params;
params = {};
}
var filesInformation = {};
files.forEach(function (fileName) {
var index = "files[" + fileName + "]";
filesInformation[index] = fs.createReadStream(fileName);
});
return postApiCallWithFormData('project/' + projectName + '/update-file', extend(filesInformation, params), callback);
},
/**
* Delete file from Crowdin project. All the translations will be lost without ability to restore them.
* @param projectName {String} Should contain the project identifier
* @param fileName {String} Name of file to delete.
* @param callback {Function} Callback to call on function completition.
*/
deleteFile: function (projectName, fileName, callback) {
return postApiCallWithFormData('project/' + projectName + '/delete-file', { file: fileName }, callback);
},
/**
* Upload existing translations to your Crowdin project
* @param projectName {String} Should contain the project identifier
* @param files {Array} Translated files array. Array keys should contain file names in Crowdin.
* Note! 20 files max are allowed to upload per one time file transfer.
* @param language {String} Target language. With a single call it's possible to upload translations for several files but only into one of the languages
* @param params {Object} Information about updated files.
* @param callback {Function} Callback to call on function completition.
*/
updateTranslations: function (projectName, files, language, params, callback) {
if (callback === undefined) {
callback = params;
params = {};
}
var filesInformation = {
language: language
};
files.forEach(function (fileName) {
var index = "files[" + fileName + "]";
filesInformation[index] = fs.createReadStream(fileName);
});
return postApiCallWithFormData('project/' + projectName + '/upload-translation', extend(filesInformation, params), callback);
},
/**
* Track your Crowdin project translation progress by language.
* @param projectName {String} Should contain the project identifier.
* @param callback {Function} Callback which returns object with information.
*/
translationStatus: function (projectName, callback) {
postApiCall('project/' + projectName + '/status', callback);
},
/**
* Get Crowdin Project details.
* @param projectName {String} Should contain the project identifier.
* @param callback {Function} Callback which returns object with information.
*/
projectInfo: function (projectName, callback) {

@@ -95,5 +239,2 @@ postApiCall('project/' + projectName + '/info', callback);

},
supportedLanguages: function (callback) {
getApiCall('supported-languages', callback);
},
/**

@@ -108,2 +249,47 @@ * Build ZIP archive with the latest translations. Please note that this method can be invoked only once per 30 minutes (there is no such

/**
* Edit Crowdin project
* @param projectName {String} Name of the project to change
* @param params {Object} New parameters for the project.
* @param callback {Function} Callback to call on function completition.
*/
editProject: function (projectName, params, callback) {
return postApiCallWithFormData('project/' + projectName + '/edit-project', params, callback);
},
/**
* Delete Crowdin project with all translations.
* @param projectName {String} Name of the project to delete.
* @param callback {Function} Callback to call on function completition.
*/
deleteProject: function (projectName, callback) {
return postApiCall('project/' + projectName + '/delete-project', callback);
},
/**
* Add directory to Crowdin project.
* @param projectName {String} Should contain the project identifier.
* @param directory {String} Directory name (with path if nested directory should be created).
* @param callback {Function} Callback to call on function completition.
*/
createDirectory: function (projectName, directory, callback) {
return postApiCall('project/' + projectName + '/add-directory', { name: directory}, callback);
},
/**
* Rename directory or modify its attributes. When renaming directory the path can not be changed (it means new_name parameter can not contain path, name only).
* @param projectName {String} Full directory path that should be modified (e.g. /MainPage/AboutUs).
* @param directory {String} New directory name.
* @param params {Object} New parameters for the directory.
* @param callback {Function} Callback to call on function completition.
*/
changeDirectory: function (projectName, directory, params, callback) {
return postApiCallWithFormData('project/' + projectName + '/change-directory', { name: directory }, params, callback);
},
/**
* Delete Crowdin project directory. All nested files and directories will be deleted too.
* @param projectName {String} Should contain the project identifier.
* @param directory {String} Directory path (or just name if the directory is in root).
* @param callback {Function} Callback to call on function completition.
*/
deleteDirectory: function (projectName, directory, callback) {
return postApiCall('project/' + projectName + '/delete-directory', { name: directory}, callback);
},
/**
* Download Crowdin project glossaries as TBX file.

@@ -113,3 +299,43 @@ */

return getApiRequest('project/' + projectName + '/download-glossary');
},
/**
* Upload your glossaries for Crowdin Project in TBX file format.
* @param projectName {String} Should contain the project identifier.
* @param fileNameOrStream {String} Name of the file to upload or stream which contains file to upload.
* @param callback {Function} Callback to call on function completition.
*/
uploadGlossary: function (projectName, fileNameOrStream, callback) {
if (typeof fileNameOrStream === "string") {
fileNameOrStream = fs.createReadStream(fileNameOrStream);
}
return postApiCallWithFormData('project/' + projectName + '/upload-glossary', { file: fileNameOrStream }, callback);
},
/**
* Download Crowdin project Translation Memory as TMX file.
* @param callback {Function} Callback to call on function completition.
*/
downloadTranslationMemory: function (projectName, callback) {
return postApiCall('project/' + projectName + '/download-tm', callback);
},
/**
* Upload your Translation Memory for Crowdin Project in TMX file format.
* @param projectName {String} Should contain the project identifier.
* @param fileNameOrStream {String} Name of the file to upload or stream which contains file to upload.
* @param callback {Function} Callback to call on function completition.
*/
uploadTranslationMemory: function (projectName, fileNameOrStream, callback) {
if (typeof fileNameOrStream === "string") {
fileNameOrStream = fs.createReadStream(fileNameOrStream);
}
return postApiCallWithFormData('project/' + projectName + '/upload-tm', { file: fileNameOrStream }, callback);
},
/**
* Get supported languages list with Crowdin codes mapped to locale name and standardized codes.
* @param callback {Function} Callback to call on function completition.
*/
supportedLanguages: function (callback) {
getApiCall('supported-languages', callback);
}
};

25

index.js

@@ -28,11 +28,24 @@ /*jslint node:true*/

api.setKey(config.api_key);
/*api.projectInfo(config.project_identifier, function (err, data) {
var handleTestResult = function (err, data) {
if (err) {
throw err;
}
console.log(data);
});*/
/*api.supportedLanguages(function (err, data) {
console.log(data);
});*/
};
//api.projectInfo(config.project_identifier, handleTestResult);
//api.supportedLanguages(handleTestResult);
//api.downloadTranslations(config.project_identifier, 'es').pipe(fs.createWriteStream('es.zip'));
api.downloadAllTranslations(config.project_identifier).pipe(fs.createWriteStream('all.zip'));
//api.downloadAllTranslations(config.project_identifier).pipe(fs.createWriteStream('all.zip'));
//api.downloadTranslationMemory(config.project_identifier).pipe(fs.createWriteStream('cordova.tmx'));
//api.uploadGlossary(config.project_identifier, 'cordova.tbx');
//api.uploadGlossary(config.project_identifier, fs.createReadStream('cordova.tbx'));
//api.uploadTranslationMemory(config.project_identifier, 'cordova.tmx');
//api.createDirectory(config.project_identifier, 'test', handleTestResult);
//api.deleteDirectory(config.project_identifier, 'test', handleTestResult);
//api.changeDirectory(config.project_identifier, 'test', { new_name: 'test1', title: 'Test directory', export_pattern: '%original_path%/%two_letters_code%' }, handleTestResult);
//api.changeDirectory(config.project_identifier, 'test1', { new_name: 'test', title: '', export_pattern: 'test' }, handleTestResult);
//api.editProject(config.project_identifier, { name: 'Cordova test 1' }, handleTestResult);
//api.addFile(config.project_identifier, ['test/1.md', 'test/adas.md'], {}, handleTestResult);
module.exports = api;
{
"name": "crowdin-cli",
"version": "0.2.1",
"version": "0.3.0",
"description": "NodeJS client for Crowdin",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,11 +10,11 @@ # crowdin-cli

crowdin-cli download
Use `-o` parameter to change output file for the downloaded content.
crowdin-cli download -o project_all.zip
Use `-l` parameter to download only selected language. Download only Russian language and save it to ru.zip.
crowdin-cli download -l ru
You could use `-o` and `-l` together.

@@ -32,14 +32,45 @@

crowdin-cli export
## Downloading glossary
You could download glossary which you create inside your CrowdIn project as a TBX file.
Use command to save glossary as project.tbx file.
Use command to save glossary as `projectname.tbx` file. Where the `projectname` is name of the project in the `crowdin.yaml`.
crowdin-cli downloadGlossary
Use command below to save glossary as technical.tbx
Use command below to save glossary as `technical.tbx`
crowdin-cli downloadGlossary -o technical.tbx
## Uploading glossary
You could upload your existing glossary, stored in TBX file, to use inside your CrowdIn project.
Use command to upload glossary in `projectname.tbx` file. Where the `projectname` is name of the project in the `crowdin.yaml`.
crowdin-cli uploadGlossary
Use command below to upload glossary stored in `technical.tbx`
crowdin-cli uploadGlossary -s technical.tbx
## Downloading translation memory
You could download translation memory which you create inside your CrowdIn project as a TBX file.
Use command to save glossary as `projectname.tmx` file. Where the `projectname` is name of the project in the `crowdin.yaml`.
crowdin-cli downloadTM
Use command below to save glossary as `technical.tmx`
crowdin-cli downloadTM -o technical.tmx
## Uploading translation memory
You could upload your existing translation memory files, stored in TMX file, to use inside your CrowdIn project.
Use command to upload glossary in `projectname.tmx` file. Where the `projectname` is name of the project in the `crowdin.yaml`.
crowdin-cli uploadTM
Use command below to upload glossary stored in `technical.tmx`
crowdin-cli uploadTM -s technical.tmx

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc