Search code examples
rtranslationgoogle-translate

Translating text in R


When looking for a solution to translate text within R, I got a lot of pretty old answers, proposing to use the package translateR. The best answer I found is this one.

The answer is 6 years old and in the meantime translateR is no longer part of the CRAN repository (anyone know why?). I was wondering if there are better options by now, that use a package that is in the CRAN repository.

My example data is as follows;

translate <- data.frame(sentences = c("This needs to be translated to Dutch",
               "This also needs to be translated to Dutch",
               "Just as this one has to"))

What is currently the best option to translate text within R?


Solution

  • You can use the deeplr package which uses deepl's API. Deepl is supposedly much more accurate than Google translate.

    library(deeplr)
    translate2(text = translate$sentences, 
               source_lang = "EN",
               target_lang = "NL",
               auth_key = "your_key")
    
    #[1] "Dit moet vertaald worden naar het Nederlands"    
    #[2] "Dit moet ook vertaald worden naar het Nederlands"
    #[3] "Net als deze moet"