Created
October 22, 2018 09:43
-
-
Save kuldipem/c2494ae90cddfc68eebc41849c7d7fc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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