Skip to content

Commit b1d2392

Browse files
committed
add support for model parameter
1 parent b1c0d25 commit b1d2392

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/translate/src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ Translate.prototype.getLanguages = function(target, callback) {
312312
* is written in.
313313
* @param {string} options.to - The ISO 639-1 language code to translate the
314314
* input to.
315+
* @param {string} options.model - **Note:** Users must be whitelisted to use
316+
* this parameter. You can use this parameter to take advantage of Neural
317+
* Machine Translation. Possible values are 'base' and 'nmt'.
315318
* @param {function} callback - The callback function.
316319
* @param {?error} callback.err - An error returned while making this request.
317320
* @param {object|object[]} callback.translations - If a single string input was
@@ -388,6 +391,10 @@ Translate.prototype.translate = function(input, options, callback) {
388391
if (options.to) {
389392
query.target = options.to;
390393
}
394+
395+
if (options.model) {
396+
query.model = options.model;
397+
}
391398
}
392399

393400
if (!query.target) {

packages/translate/test/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,22 @@ describe('Translate', function() {
406406
});
407407
});
408408

409+
describe('options.model', function() {
410+
it('should set the model option when available', function(done) {
411+
var fakeOptions = {
412+
model: 'nmt',
413+
to: 'es'
414+
};
415+
416+
translate.request = function(reqOpts) {
417+
assert.strictEqual(reqOpts.json.model, 'nmt');
418+
done();
419+
};
420+
421+
translate.translate(INPUT, fakeOptions, assert.ifError);
422+
});
423+
});
424+
409425
it('should make the correct API request', function(done) {
410426
translate.request = function(reqOpts) {
411427
assert.strictEqual(reqOpts.uri, '');

0 commit comments

Comments
 (0)