Skip to content

Commit

Permalink
add support for model parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Nov 10, 2016
1 parent b1c0d25 commit b1d2392
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/translate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ Translate.prototype.getLanguages = function(target, callback) {
* is written in.
* @param {string} options.to - The ISO 639-1 language code to translate the
* input to.
* @param {string} options.model - **Note:** Users must be whitelisted to use
* this parameter. You can use this parameter to take advantage of Neural
* Machine Translation. Possible values are 'base' and 'nmt'.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object|object[]} callback.translations - If a single string input was
Expand Down Expand Up @@ -388,6 +391,10 @@ Translate.prototype.translate = function(input, options, callback) {
if (options.to) {
query.target = options.to;
}

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

if (!query.target) {
Expand Down
16 changes: 16 additions & 0 deletions packages/translate/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ describe('Translate', function() {
});
});

describe('options.model', function() {
it('should set the model option when available', function(done) {
var fakeOptions = {
model: 'nmt',
to: 'es'
};

translate.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.model, 'nmt');
done();
};

translate.translate(INPUT, fakeOptions, assert.ifError);
});
});

it('should make the correct API request', function(done) {
translate.request = function(reqOpts) {
assert.strictEqual(reqOpts.uri, '');
Expand Down

0 comments on commit b1d2392

Please sign in to comment.