Last active
December 22, 2020 09:11
-
-
Save phydev/2f745594d91b09c95d196d1e3fbbd0d6 to your computer and use it in GitHub Desktop.
Using Google Cloud Translation in R for translating data dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(googleLanguageR) | |
# STEP1: Generate access key for google cloud | |
# read more: https://cloud.google.com/translate/docs/basic/setup-basic | |
gl_auth('auth_key.json') # access Google Cloud Translation API with your credentials | |
df <- read.csv('german_data_dictionary.csv') # read data | |
# translate 'Content' and store in a new column 'Content_EN' | |
df <- df %>% mutate(Content_EN = gl_translate(Content, source='de', target = 'en')$translatedText) | |
df <- df %>% relocate(Content_EN, .after=Label) | |
# save to external file | |
write.csv(df_en, "english_data_dictionary.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment