-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
108 lines (80 loc) · 3.67 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# deeplr
The DeepL Translator made headlines for providing better translations than Google etc. ```deeplr``` is a quick & dirty coded package that contains functions - ```translate_vec()``` and ```translate_df()``` - that access the DeepL API. I was inspired by the [translateR package](https://github.com/ChristopherLucas/translateR) package.
To access the API you need to get your own API key from deeplr: https://www.deepl.com/api-contact.html.
Beware of the API request limits. See https://www.deepl.com/api-reference.html.
* "The request size should not exceed 30kbytes. The maximum number of texts to be translated within one request should not exceed 50."
* "Please ensure your client does not exceed the limits as specified in the quota documentation delivered to you."
## Installation: How do I get the package?
```{r eval=FALSE, message=FALSE, warning=FALSE, include=TRUE, paged.print=FALSE}
# Development version
# install.packages("devtools")
devtools::install_github("paulcbauer/deeplr")
```
## Example: How do I use the package?
You can feed ```translate_vec()``` with a single string, a vector of strings (class "character"). You can feed ```translate_df()``` with a dataframe that contains a column of class "character".
```{r eval=FALSE, message=FALSE, warning=FALSE, include=TRUE, paged.print=FALSE}
# Load the package
library(deeplr)
# Translate a single string/character vector
dat <- c("La seule facon de savoir ce qui se passe est de perturber le systeme.",
"The whole problem with the world is that fools are always so certain of themselves")
# Without language detection and without adding set/detected source language.
translate_vec(dataset = dat,
source.lang = "EN",
target.lang = "DE",
auth_key = "enter you auth key here")
dat <- c("A dog.",
"Un chien.",
"Un perro.",
"Un cane.",
"Een hond.")
# With language detection and with adding set/detected source language.
translate_vec(dataset = dat,
source.lang = "detect",
target.lang = "DE",
add.source.lang = TRUE,
auth_key = "enter you auth key here")
# Translate a column in a dataframe
dat <- data.frame(text = c("La seule facon de savoir ce qui se passe est de perturber
le systeme.",
"The whole problem with the world is that fools are always so
certain of themselves"))
# Without language detection and without adding set/detected source language.
translate_df(dataset = dat,
column.name = "text",
source.lang = "EN",
target.lang = "DE",
auth_key = "enter you auth key here")
dat <- data.frame(text = c("A dog.",
"Un chien.",
"Un perro.",
"Un cane.",
"Een hond."))
# With language detection and with adding set/detected source language.
translate_df(dataset = dat,
column.name = "text",
source.lang = "detect",
target.lang = "DE",
add.source.lang = TRUE,
auth_key = "enter you auth key here")
# well...
```
## Next steps
* Increase efficiency of code
* Add option to output multiple languages
* Test robustness.. encoding issues etc.
## License
License: CC BY-NC-SA 4.0