Skip to content

Commit

Permalink
style: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tin900 committed Aug 30, 2023
1 parent 8721ad4 commit 046ac68
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 41 deletions.
6 changes: 3 additions & 3 deletions R/create_translation_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#' translations <- create_translation_table(words, languages)
#' print(translations)
create_translation_table <- function(words, languages) {
Original_word <- NULL
translations <- data.frame(Original_word = words)
original_word <- NULL
translations <- data.frame(original_word = words)

for (language in languages) {
column_name <- language
translations <- translations %>%
dplyr::mutate("{column_name}" := purrr::map_chr(
Original_word,
original_word,
~ google_translate(., target_language = language)
))
}
Expand Down
4 changes: 2 additions & 2 deletions R/google_translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' \donttest{
#' google_translate("I love languages", target_language = "es")
#' text_to_translate <- c("the", "quick", "brown")
#' google_translate (text_to_translate, "fr", "en")
#' google_translate(text_to_translate, "fr", "en")
#' }
google_translate <- function(text, target_language = "en", source_language = "auto") {
is_vector <- is.vector(text) && length(text) > 1
Expand All @@ -31,7 +31,7 @@ google_translate <- function(text, target_language = "en", source_language = "au
if (is_vector) {
responses <- purrr::map(formatted_link, httr::GET)

translations <- purrr::map(responses, ~{
translations <- purrr::map(responses, ~ {
translation <- httr::content(.x) %>%
rvest::html_nodes("div.result-container") %>%
rvest::html_text()
Expand Down
29 changes: 4 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
---
editor_options:
markdown:
wrap: 72
---

# polyglotr <a href='https://github.com/Tomeriko96/polyglotr'><img src="man/figures/hex-polyglotr.png" style="float:right; height:200px;" height="200" align="right"/></a>

[![CodeFactor](https://www.codefactor.io/repository/github/Tomeriko96/polyglotr/badge)](https://www.codefactor.io/repository/github/Tomeriko96/polyglotr)
[![R-CMD-check](https://github.com/Tomeriko96/polyglotr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Tomeriko96/polyglotr/actions/workflows/R-CMD-check.yaml)
[![CRAN
status](https://www.r-pkg.org/badges/version/polyglotr)](https://CRAN.R-project.org/package=polyglotr/)
<a href="https://diffify.com/R/polyglotr" target="_blank"><img src="https://diffify.com/diffify-badge.svg" alt="The diffify page for the R package polyglotr" style="width: 100px; max-width: 100%;"/></a>
[![CRAN last month
downloads](https://cranlogs.r-pkg.org/badges/last-month/polyglotr?color=green/)](https://cran.r-project.org/package=polyglotr/)
[![CRAN
downloads](https://cranlogs.r-pkg.org/badges/grand-total/polyglotr?color=green/)](https://cran.r-project.org/package=polyglotr/)
[![CodeFactor](https://www.codefactor.io/repository/github/Tomeriko96/polyglotr/badge)](https://www.codefactor.io/repository/github/Tomeriko96/polyglotr) [![R-CMD-check](https://github.com/Tomeriko96/polyglotr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Tomeriko96/polyglotr/actions/workflows/R-CMD-check.yaml) [![CRAN status](https://www.r-pkg.org/badges/version/polyglotr)](https://CRAN.R-project.org/package=polyglotr/) <a href="https://diffify.com/R/polyglotr" target="_blank"><img src="https://diffify.com/diffify-badge.svg" alt="The diffify page for the R package polyglotr" style="width: 100px; max-width: 100%;"/></a> [![CRAN last month downloads](https://cranlogs.r-pkg.org/badges/last-month/polyglotr?color=green/)](https://cran.r-project.org/package=polyglotr/) [![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/polyglotr?color=green/)](https://cran.r-project.org/package=polyglotr/)

R package to translate text.

# Overview

The `polyglotr` package is a language translation tool for the R
programming language. It provides convenient functions to translate text
using different (free) translation services. This vignette will guide
you through the usage of the package and demonstrate how to translate
text and files in various languages.
The `polyglotr` package is a language translation tool for the R programming language. It provides convenient functions to translate text using different (free) translation services. This vignette will guide you through the usage of the package and demonstrate how to translate text and files in various languages.

Currently, the package has functions to communicate with the following
services:
Currently, the package has functions to communicate with the following services:

- Google Translate API

Expand All @@ -50,9 +31,7 @@ remotes::install_github("Tomeriko96/polyglotr")

# Usage

To demonstrate the usage of the `polyglotr` package, let's consider an
example where we translate a list of texts into multiple languages using
the `create_translation_table` function.
To demonstrate the usage of the `polyglotr` package, let's consider an example where we translate a list of texts into multiple languages using the `create_translation_table` function.

```{r}
texts <- c("Hello, how are you?",
Expand Down
2 changes: 1 addition & 1 deletion man/google_translate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ skip_if_http_error <- function() {
"&q=",
formatted_text
)
skip_if(httr::http_error(httr::GET(formatted_link)))
testthat::skip_if(httr::http_error(httr::GET(formatted_link)))
}
12 changes: 3 additions & 9 deletions vignettes/Linguee.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ knitr::opts_chunk$set(
The `polyglotr` package provides convenient functions to access the Linguee API and retrieve translations, examples, and external sources. This vignette demonstrates the usage of three key functions: `linguee_external_sources()`, `linguee_translation_examples()`, and `linguee_word_translation()`.

```{r}
library(polyglotr)
```


Expand All @@ -31,11 +29,9 @@ library(polyglotr)
The `linguee_external_sources()` function retrieves external sources using the Linguee Translation API. Here's an example usage:

```{r}
external_sources <- linguee_external_sources("hello", src = "en", dst = "de" )
external_sources <- linguee_external_sources("hello", src = "en", dst = "de")
print(external_sources)
```


Expand All @@ -45,8 +41,7 @@ The `linguee_translation_examples()` function provides translation examples usin


```{r}
translation_examples <- linguee_translation_examples("hello", src = "en", dst = "de")
translation_examples <- linguee_translation_examples("hello", src = "en", dst = "de")
print(translation_examples)
```
Expand All @@ -59,8 +54,7 @@ The `linguee_word_translation()` function translates a word using the Linguee Tr


```{r}
word_translation <- linguee_word_translation("hello", source_language = "en", target_language = "de")
word_translation <- linguee_word_translation("hello", source_language = "en", target_language = "de")
print(word_translation)
```
Expand Down

0 comments on commit 046ac68

Please sign in to comment.