Translate text to another language
npm i @superfaceai/one-sdk
const { SuperfaceClient } = require('@superfaceai/one-sdk');
// You can manage tokens here: https://superface.ai/insights
const sdk = new SuperfaceClient({ sdkAuthToken: '<< Login to get your token >>' });
async function run() {
// Load the profile
const profile = await sdk.getProfile('language/translate@1.0.2');
// Use the profile
const result = await profile
.getUseCase('TranslateText')
.perform({
text: 'Enjoy your stay.',
targetLanguage: 'ES'
}, {
provider: 'mock'
});
// Handle the result
try {
const data = result.unwrap();
console.log(data);
} catch (error) {
console.error(error);
}
}
run();
{
"text": "Enjoy your stay.",
"targetLanguage": "ES"
}
{
"text": "Disfrute de su estancia.",
"sourceLanguage": "EN"
}