tomeriko96 / polyglotr Goto Github PK
View Code? Open in Web Editor NEWR package to translate text
Home Page: https://tomeriko96.github.io/polyglotr/
License: Other
R package to translate text
Home Page: https://tomeriko96.github.io/polyglotr/
License: Other
Describe the bug
google_translate()
function is not vectorised. Passing a character vector into the function results in an error: Error in parse_url(url) : length(url) == 1 is not TRUE
Steps to reproduce the behavior:
library(polyglotr)
text_to_translate <- c("the", "quick", "brown")
google_translate (text_to_translate, "fr", "en")
Expected behavior
If supplying a vector or list to the function, it should parse each element and return a vector where each element is the translation of an element in the supplied vector.
Currently, it returns an error in some common use cases. Eg if trying to use dplyr::mutate()
on a data frame to create a new column with the translation of an existing column the following code will return an error
df %>%
mutate(translated_text = google_translate(original_text, "fr", "en"))
And to workaround you then need to use additional code, eg:
df %>%
mutate(translated_text = map(original_text, google_translate, "fr", "en")) %>%
unnest_wider(translated_text)
Desktop (please complete the following information):
Thanks for your work developing this package. It is handy and will likely be even easier to use if the functions can accept vectors of text to be translated.
For wmcloud method look into other formats. For instance, the webpage format should retrieve a html file.
Other formats:
First release:
usethis::use_cran_comments()
Title:
and Description:
@return
and @examples
Authors@R:
includes a copyright holder (role 'cph')Prepare for release:
git pull
urlchecker::url_check()
devtools::check(remote = TRUE, manual = TRUE)
devtools::check_win_devel()
rhub::check_for_cran()
git push
Submit to CRAN:
usethis::use_version('major')
devtools::submit_cran()
Wait for CRAN...
git push
usethis::use_github_release()
usethis::use_dev_version()
git push
The table on the following webpage (https://cloud.google.com/translate/docs/languages) contains a table.
Hi,
Thank you for making this package, it is very useful. However, I encountered an issue when translating from a language with special characters to English, for example from French or Arabic. The returned transcription is partly or totally unreadable :
The issue:
# in French
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 = polyglotr::google_translate(text_fr, "en", "fr")
The result is "The Saône has its source at Vioménil in the Pré-Vosges at an altitude of 405 m. The river confluences with the Rhône 473.3 km further." while I'm expecting Saône instead of Saône
# in Arabic
text_ar = "يتدفقُ النيل عبر الصحراء السودانية إلى مصر باتجاه الشمال ويمر في مدينةُ القاهرة الواقعة على دلتا النهر الكبيرة (دلتا النيل)، ثم يعبر النهر مدينتي دمياط ورشيد ويصب ..."
ar_to_en = polyglotr::google_translate(text_ar, "en", "ar")
The result is "اÙÙÙ٠عبر اÙصØراء اÙسÙداÙÙØ© Ùصر ... (دÙتا اÙÙÙÙ)Ø ±".
What I've tried:
My guess is that it is an encoding issue. I have tried to use enc2utf8(mytext)
or Encoding<-(value = mytext, enc2utf8)
to indicate the UTF-8 encoding but it didn't work. The encoding of the returned transaltion is "unknown" (Encoding(ar_to_en)
).
Have you ever encountered this problem?
Thank you.
Desktop:
Additional context:
I've tried to use mymemory_translate instead but I've reached the characters limit and given the supported languages, I'd prefer using google translate anyway.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.