From b1d239273eb340d97301646f7347203b07b85cf9 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Thu, 10 Nov 2016 16:32:04 -0500 Subject: [PATCH] add support for model parameter --- packages/translate/src/index.js | 7 +++++++ packages/translate/test/index.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/translate/src/index.js b/packages/translate/src/index.js index ba6bcd2b1bd8..8bea34585395 100644 --- a/packages/translate/src/index.js +++ b/packages/translate/src/index.js @@ -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 @@ -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) { diff --git a/packages/translate/test/index.js b/packages/translate/test/index.js index f9ce1c192902..58649e818e0c 100644 --- a/packages/translate/test/index.js +++ b/packages/translate/test/index.js @@ -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, '');