Skip to content

Commit

Permalink
minor fixes per PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Nov 11, 2016
1 parent 023359d commit b68c187
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/translate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Translate.prototype.getLanguages = function(target, callback) {
* is written in.
* @param {string} options.model - **Note:** Users must be whitelisted to use
* this parameter. Set the model type requested for this translation. Please
* refer to the upstread documentation for possible values.
* refer to the upstream documentation for possible values.
* @param {string} options.to - The ISO 639-1 language code to translate the
* input to.
* @param {function} callback - The callback function.
Expand Down Expand Up @@ -376,35 +376,35 @@ Translate.prototype.getLanguages = function(target, callback) {
Translate.prototype.translate = function(input, options, callback) {
input = arrify(input);

var query = {
var body = {
q: input,
format: options.format || (isHtml(input[0]) ? 'html' : 'text')
};

if (is.string(options)) {
query.target = options;
body.target = options;
} else {
if (options.from) {
query.source = options.from;
body.source = options.from;
}

if (options.to) {
query.target = options.to;
body.target = options.to;
}

if (options.model) {
query.model = options.model;
body.model = options.model;
}
}

if (!query.target) {
if (!body.target) {
throw new Error('A target language is required to perform a translation.');
}

this.request({
method: 'POST',
uri: '',
json: query
json: body
}, function(err, resp) {
if (err) {
callback(err, null, resp);
Expand All @@ -413,7 +413,7 @@ Translate.prototype.translate = function(input, options, callback) {

var translations = resp.data.translations.map(prop('translatedText'));

if (query.q.length === 1) {
if (body.q.length === 1) {
translations = translations[0];
}

Expand Down
1 change: 1 addition & 0 deletions packages/translate/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('Translate', function() {
'https://www.googleapis.com/auth/cloud-platform'
]);
assert.deepEqual(calledWith.packageJson, require('../package.json'));
assert.strictEqual(calledWith.projectIdRequired, false);
});

describe('Using an API Key', function() {
Expand Down

0 comments on commit b68c187

Please sign in to comment.