Translate character vectors via the Google Translate API
Value
A tibble of translatedText
and detectedSourceLanguage
and text
of length equal to the vector of text you passed in.
Details
You can translate a vector of strings, although if too many for one call then it will be broken up into one API call per element. This is the same cost as charging is per character translated, but will take longer.
If translating HTML set the format = "html"
.
Consider removing anything not needed to be translated first,
such as JavaScript and CSS scripts. See example on how to do this with rvest
The API limits in three ways: characters per day, characters per 100 seconds, and API requests per 100 seconds. All can be set in the API manager https://console.developers.google.com/apis/api/translate.googleapis.com/quotas
See also
https://cloud.google.com/translate/docs/reference/translate
Other translations:
gl_translate_detect()
,
gl_translate_languages()
Examples
if (FALSE) { # \dontrun{
text <- "to administer medicine to animals is frequently a very difficult matter,
and yet sometimes it's necessary to do so"
gl_translate(text, target = "ja")
# translate webpages using rvest to process beforehand
library(rvest)
library(googleLanguageR)
# translate webpages
# dr.dk article
my_url <- "http://bit.ly/2yhrmrH"
## in this case the content to translate is in css selector '.wcms-article-content'
read_html(my_url) %>%
html_node(css = ".wcms-article-content") %>%
html_text %>%
gl_translate(format = "html")
} # }