Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const { translate } = require('deepl-translator');
const SOURCE_LAN = 'EN';
const DESTINATION_LAN = 'DE';
const translateTitle = function(txt, cb){
translate(txt, DESTINATION_LAN, SOURCE_LAN)
.then(res => {
/** res will be
* {
* targetLanguage: 'DE', // in which the text will be translated
* resolvedSourceLanguage: 'EN', // DeepL Api's detected languge of the given text
* translation: '[TXT]' // Translated text
* }
* */
cb(res.translation);
})
.catch((err)=>{
cb(err);
});
};
module.exports = {
translateTitle
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment