Coder Social home page Coder Social logo

tomeriko96 / polyglotr Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 2.0 5.25 MB

R package to translate text

Home Page: https://tomeriko96.github.io/polyglotr/

License: Other

R 100.00%
language r rpackage rstats translation google-translate googletranslate pons mymemory-api mymemorytranslator

polyglotr's People

Contributors

tin900 avatar tomeriko96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mohamed-180

polyglotr's Issues

`google_translate` doesn't accept vectors of text as input

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):

  • OS: [OS X]
  • R version [4.2.2]

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.

Broaden wmcloud functionality

For wmcloud method look into other formats. For instance, the webpage format should retrieve a html file.
Other formats:

  • text
  • json
  • webpage
  • markdown
  • html
  • svg

Release polyglotr 1.0.0

First release:

Prepare for release:

  • git pull
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('major')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Encoding issue

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:

  • OS: Windows
  • R version : 4.3.1
  • RStudio version : 2023.09.0

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.