Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kuldipem
Created October 22, 2018 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuldipem/c2494ae90cddfc68eebc41849c7d7fc5 to your computer and use it in GitHub Desktop.
Save kuldipem/c2494ae90cddfc68eebc41849c7d7fc5 to your computer and use it in GitHub Desktop.
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