Skip to content

Commit

Permalink
add languages info method
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin committed Aug 27, 2015
1 parent 30cf068 commit f5c5740
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var request = require('request');
var _ = require('lodash');
var apiUrl = '/api/2/project/';
var apiUrl = '/api/2/';
var host = 'https://transifex.com';
/**
*
Expand Down Expand Up @@ -38,14 +38,14 @@ var transifex = function (config) {
return makeRequest(url);
};
var getLanguages = function () {
var url = `${config.projectSlug}/?details`;
var url = `project/${config.projectSlug}/?details`;
return getResponse(url).then(function (data) {
return data.teams;
});
};
var resourceFile = `${config.projectSlug}/resource/${config.resourceSlug}/`;
var getTranslation = function (langCode) {
var url = `${resourceFile}translation/${langCode}/?mode=reviewed`;
var url = `project/${resourceFile}translation/${langCode}/?mode=reviewed`;
return getResponse(url).then(function (data) {
langCode = langCode.replace('_', '-');
return {lang: langCode, content: data.content};
Expand All @@ -59,7 +59,7 @@ var transifex = function (config) {
};

var updateResourceFile = function (content) {
var url = `${resourceFile}content/`;
var url = `project/${resourceFile}content/`;
return getResponse(url).then(function (res) {
var contentFromResource = JSON.parse(res.content);
return _.merge(contentFromResource, content);
Expand All @@ -68,9 +68,20 @@ var transifex = function (config) {
});
};

var getLanguagesInfo = function (content) {
var url = `languages/`;
return getResponse(url).then(function (languages) {
return languages.map(function (lang) {
lang.code = lang.code.replace('_', '-');
return lang;
});
})
};

return {
getTranslatedResources: getTranslatedResources,
updateResourceFile: updateResourceFile
updateResourceFile: updateResourceFile,
getLanguagesInfo: getLanguagesInfo
};
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tau-transifex",
"version": "0.2.0",
"version": "0.3.0",
"description": "Simple API for request to transifex REST API",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit f5c5740

Please sign in to comment.