Last active
July 1, 2021 18:31
-
-
Save kumeS/26a7a602070365595a0b552e201079d5 to your computer and use it in GitHub Desktop.
This R function performs DeepL API on MacOSX/LINUX
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
##' @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