prep_translate <- function(string, type) {
url <- glue::glue("http://api.funtranslations.com/translate/", type, "?text=",
htmltools::urlEncodePath(string))
resp <- httr::GET(url)
result <- jsonlite::fromJSON(httr::content(resp, "text"),
simplifyVector = FALSE)
if (httr::http_error(resp)) {
stop(
sprintf(
"Fun Translation API request failed [%s]\n%s",
httr::status_code(resp),
result$error$message
),
call. = FALSE
)
} else {
result$contents$translated
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.