Skip to content

Instantly share code, notes, and snippets.

@phydev
Last active December 22, 2020 09:11
Show Gist options
  • Save phydev/2f745594d91b09c95d196d1e3fbbd0d6 to your computer and use it in GitHub Desktop.
Save phydev/2f745594d91b09c95d196d1e3fbbd0d6 to your computer and use it in GitHub Desktop.
Using Google Cloud Translation in R for translating data dictionaries
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