TranslatorTextClient Library with typescript type definitions for node.js and browser.
npm install @azure/cognitiveservices-translatortextThis package contains an isomorphic SDK for TranslatorTextClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
``bash`
npm install @azure/cognitiveservices-translatortext
#### nodejs - Authentication, client creation and languages translator as an example written in TypeScript.
##### Install @azure/ms-rest-azure-js
`bash`
npm install @azure/ms-rest-azure-js
##### Sample code
The following sample translates the given text which is in Chinese to English. To know more, refer to the Azure Documentation on Translator
`javascript
const { TranslatorTextClient } = require("@azure/cognitiveservices-translatortext");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");
async function main() {
const translatorTextKey =
process.env["translatorTextKey"] || "
const translatorTextEndPoint =
process.env["translatorTextEndPoint"] || "
const cognitiveServiceCredentials = new CognitiveServicesCredentials(
translatorTextKey
);
const client = new TranslatorTextClient(
cognitiveServiceCredentials,
translatorTextEndPoint
);
const text = [
{
text: "你好,世界"
}
];
client.translator
.detect(text)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}
main();
`
#### browser - Authentication, client creation and languages translator as an example written in JavaScript.
##### Sample code
- index.html
`html``