Skip to content

Instantly share code, notes, and snippets.

@kumeS
Last active July 1, 2021 18:31
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 kumeS/26a7a602070365595a0b552e201079d5 to your computer and use it in GitHub Desktop.
Save kumeS/26a7a602070365595a0b552e201079d5 to your computer and use it in GitHub Desktop.
This R function performs DeepL API on MacOSX/LINUX
##' @title DeepL API on R
##'
##' @param Sentence an input string.
##' @param EN2JA a logical.
##' @param Auth_Key a string, Your Authentication Key
##'
##' @return character
##' @author Satoshi Kume
##' @export DeePL
##'
DeePL <- function(Sentence, EN2JA=TRUE, Auth_Key="Your Authentication Key"){
if(EN2JA){
a <- system(paste0('curl -s https://api-free.deepl.com/v2/translate -d "auth_key=', Auth_Key, '" -d "text=', Sentence, '" -d source_lang="EN" -d "target_lang=JA"'), intern = T)
}else{
a <- system(paste0('curl -s https://api-free.deepl.com/v2/translate -d "auth_key=', Auth_Key, '" -d "text=', Sentence, '" -d source_lang="JA" -d "target_lang=EN"'), intern = T)
}
result <- strsplit(strsplit(as.character(a), "\"text\":\"")[[1]][2], "\"}]}")[[1]][1]
return(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment