I built a simple translation function in R with Python code inside. It works well for one string. But how do should apply it for a list of strings?
string <- c("cat")
string <- c("cat", "dog")
translations.df <- TranslateEnglishStringToFrenchString(string)
View(translations.df)
TranslateEnglishStringToFrenchString <- function(string){
functionToApply <- function(string){
reticulate::py_run_string("from deep_translator import GoogleTranslator")
reticulate::py_run_string("translatedString = GoogleTranslator(source='en', target='fr').translate(r.string)")
translatedString <- py$translatedString
.df <- data.frame(string, translatedString)
return(.df)
}
toReturn.df <- do.call(rbind, lapply(string, functionToApply))
return(toReturn.df)
}
For the moment, it returns the following error :
Error in py_run_string_impl(code, local, convert) : NotValidPayload: ['cat', 'dog'] --> text must be a valid text with maximum 5000 character, otherwise it cannot be translated
Nevertheless, it is clear that it is not a question of maximum characters here...
Thank you very much for your help !