Comments (5)
Hi @lbajemon ,
Thank you for reporting this issue. I have tested the code and can confirm the problem you've described.
I'll be looking into it and will provide an update as soon as I have more information.
from polyglotr.
hi @lbajemon,
Could you try the following function:
google_translate_test <- function(text, target_language = "en", source_language = "auto") {
is_vector <- is.vector(text) && length(text) > 1
formatted_text <- urltools::url_encode(text)
formatted_link <- paste0(
"https://translate.google.com/m?tl=",
target_language, "&sl=", source_language,
"&q=",
formatted_text
)
if (is_vector) {
responses <- purrr::map(formatted_link, httr::GET)
translations <- purrr::map(responses, ~ {
translation <- httr::content(.x) %>%
rvest::html_nodes("div.result-container") %>%
rvest::html_text()
translation <- urltools::url_decode(translation)
translation <- gsub("\n", "", translation)
translation
})
return(translations)
} else {
response <- httr::GET(formatted_link)
translation <- httr::content(response) %>%
rvest::html_nodes("div.result-container") %>%
rvest::html_text()
translation <- urltools::url_decode(translation)
translation <- gsub("\n", "", translation)
return(translation)
}
}
Running your examples now returns the following:
> text_fr = "La Saône prend sa source à Vioménil dans les pré-Vosges à 405 m d'altitude. La rivière conflue avec le Rhône 473,3 km plus loin."
> fr_to_en = google_translate_test(text_fr, "en", "fr")
> fr_to_en
[1] "The Saône has its source at Vioménil in the pre-Vosges at an altitude of 405 m. The river confluences with the Rhône 473.3 km further."
> # in Arabic
> text_ar = "يتدفقُ النيل عبر الصحراء السودانية إلى مصر باتجاه الشمال ويمر في مدينةُ القاهرة الواقعة على دلتا النهر الكبيرة (دلتا النيل)، ثم يعبر النهر مدينتي دمياط ورشيد ويصب ..."
> ar_to_en = google_translate_test(text_ar, "en", "ar")
> ar_to_en
[1] "The Nile flows through the Sudanese desert to Egypt towards the north and passes through the city of Cairo, located on the large river delta (Nile Delta), then the river crosses the cities of Damietta and Rosetta and flows..."
from polyglotr.
Hi @tin900, it works with this function. Thank you very much
from polyglotr.
Awesome!
Commit 72994d2 implements the bugfix.
You can install the development version of the package to use the improved google_translate()
function.
I will update the package on CRAN in the coming days as well.
from polyglotr.
The new version of the package is now available on CRAN
from polyglotr.
Related Issues (12)
- Release polyglotr 1.0.0
- get linguee api examples HOT 1
- get linguee api external sources HOT 1
- `google_translate` doesn't accept vectors of text as input HOT 3
- write linguee api vignette
- Get the supported languages for google translate HOT 1
- Broaden wmcloud functionality HOT 2
- Feat: look into the following services HOT 1
- Broaden Pons translate functionalities
- Polyglotr: translation of whole text fails, but it works for each individual chunk HOT 7
- Encoding warning and Error in `dplyr::mutate()`: when using create_translation_table HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polyglotr.