Skip to content

Commit

Permalink
doc: use new import syntax in samples (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and Ace Nassri committed Nov 17, 2022
1 parent b4d6a99 commit 6f91895
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion translate/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// [START translate_quickstart]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';
Expand Down
7 changes: 5 additions & 2 deletions translate/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const proxyquire = require(`proxyquire`).noPreserveCache();
const sinon = require(`sinon`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const translate = proxyquire(`@google-cloud/translate`, {})();
const {Translate} = proxyquire(`@google-cloud/translate`, {});
const translate = new Translate();

test.before(tools.checkCredentials);
test.before(tools.stubConsole);
Expand Down Expand Up @@ -58,6 +59,8 @@ test.cb(`should translate a string`, t => {
};

proxyquire(`../quickstart`, {
'@google-cloud/translate': sinon.stub().returns(translateMock),
'@google-cloud/translate': {
Translate: sinon.stub().returns(translateMock),
},
});
});
3 changes: 2 additions & 1 deletion translate/system-test/translate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const translate = require(`@google-cloud/translate`)();
const {Translate} = require(`@google-cloud/translate`);
const translate = new Translate();

const cwd = path.join(__dirname, `..`);
const cmd = `node translate.js`;
Expand Down
10 changes: 5 additions & 5 deletions translate/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
function detectLanguage(text) {
// [START translate_detect_language]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Creates a client
const translate = new Translate();
Expand Down Expand Up @@ -51,7 +51,7 @@ function detectLanguage(text) {
function listLanguages() {
// [START translate_list_codes]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Creates a client
const translate = new Translate();
Expand All @@ -74,7 +74,7 @@ function listLanguages() {
function listLanguagesWithTarget(target) {
// [START translate_list_language_names]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Creates a client
const translate = new Translate();
Expand Down Expand Up @@ -102,7 +102,7 @@ function listLanguagesWithTarget(target) {
function translateText(text, target) {
// [START translate_translate_text]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Creates a client
const translate = new Translate();
Expand Down Expand Up @@ -138,7 +138,7 @@ function translateText(text, target) {
function translateTextWithModel(text, target, model) {
// [START translate_text_with_model]
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
const {Translate} = require('@google-cloud/translate');

// Creates a client
const translate = new Translate();
Expand Down

0 comments on commit 6f91895

Please sign in to comment.