MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / translateTextWithModel

Function translateTextWithModel

translate/translate.js:136–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134 // const model = 'The model to use, e.g. nmt';
135
136 async function translateTextWithModel() {
137 const options = {
138 // The target language, e.g. "ru"
139 to: target,
140 // Make sure your project is on the allow list.
141 // Possible values are "base" and "nmt"
142 model: model,
143 };
144
145 // Translates the text into the target language. "text" can be a string for
146 // translating a single piece of text, or an array of strings for translating
147 // multiple texts.
148 let [translations] = await translate.translate(text, options);
149 translations = Array.isArray(translations) ? translations : [translations];
150 console.log('Translations:');
151 translations.forEach((translation, i) => {
152 console.log(`${text[i]} => (${target}) ${translation}`);
153 });
154 }
155
156 translateTextWithModel();
157 // [END translate_text_with_model]

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected