Skip to content

Instantly share code, notes, and snippets.

@dankimio
Forked from enogylop/deepl_for_google_sheets.txt
Last active February 28, 2022 14:41
Show Gist options
  • Select an option

  • Save dankimio/97c5295953f912d5e5dd1a220836e780 to your computer and use it in GitHub Desktop.

Select an option

Save dankimio/97c5295953f912d5e5dd1a220836e780 to your computer and use it in GitHub Desktop.
DeepL for Google Sheets
// Replace auth_key with a "Deepl for developer" API key
// Source: http://5.9.10.113/67485395/google-sheets-custom-function-to-translate-with-deepl-api-not-working-as-expecte
function deepl(text, sourceLang, targetLang) {
const authKey = 'xxxx-xxxx-xxxx-xxxx-xxxx'
const url = `https://api-free.deepl.com/v2/translate?auth_key=${authKey}&text=${encodeURIComponent(text)}&target_lang=${targetLang}&source_lang=${sourceLang}`
const response = UrlFetchApp.fetch(url)
const json = response.getContentText()
const data = JSON.parse(json)
return data.translations && data.translations.length > 0 ? data.translations[0].text : "No value"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment