Description Usage Arguments Details Value Author(s) Examples
Function will be able to send vtt file for translation in Google Translate API and return proper strucuture of the file back.
1 | translateVTT(fileName, sourceLang = "en", destLang, apikey)
|
fileName |
String with a path to the file you want to translate. Only one file name is accepted at the time |
sourceLang |
Source language code, 'en' is default value. |
destLang |
Destination language for translator function. Only one at the time |
apikey |
Google Translate API key |
Google Tranlation with API is paid service, however 300USD is given for free for 12 month, check cloud.google.com
Function does not return value. It is generating new file adding language code before .vtt
(C) 2019 Vladimir Zhbanko
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 | library(openssl)
library(readr)
library(magrittr)
library(stringr)
library(translateVTT)
library(translateR)
# retrieve filename
file_name <- system.file("extdata", "L0.vtt", package = "translateVTT")
path_ssh <- normalizePath(tempdir(),winslash = "/")
path_private_key <- file.path(path_ssh, "id_api")
# decrypt the key
out <- read_rds(file.path(path_ssh, "api_key.enc.rds"))
google.api.key <- decrypt_envelope(out$data,
out$iv,
out$session,
path_private_key,
password = "") %>%
unserialize()
# send one vtt file for translation
translateVTT(fileName = file_name,
sourceLang = "en",
destLang = "es",
apikey = google.api.key)
## send multiple files for translations
# create list of files to translate
filesToTranslate <-list.files("~Files/Downloads/", pattern="*.vtt", full.names=TRUE)
# make a list of languages
languages <- c("fr", "tr", "it", "id", "pt", "es", "ms", "de")
# for loop (note translation takes a while 100 translations ~ 1 hour)
for (FILE in filesToTranslate) {
# for loop for languages
for (LANG in languages) {
# translation
translateVTT(fileName = FILE, sourceLang = "en", destLang = LANG, apikey = api_key)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.