Skip to content

Instantly share code, notes, and snippets.

@bbdaniels
Created January 21, 2021 18:13
Show Gist options
  • Select an option

  • Save bbdaniels/9d8f6e0df0a7f444b027895914e6be6a to your computer and use it in GitHub Desktop.

Select an option

Save bbdaniels/9d8f6e0df0a7f444b027895914e6be6a to your computer and use it in GitHub Desktop.
Google Translate for Stata
**
cap prog drop gtrans
prog def gtrans , rclass
syntax anything
preserve
qui {
local theText = subinstr("`anything'"," ","%20",.) // HTML for whitespace
import delimited using ///
"https://translation.googleapis.com/language/translate/v2?q=`theText'&target=en&key=XXX" /// replace XXX with API key
, clear
keep v1
keep if regexm(v1,"translated")
replace v1 = substr(v1,strpos(v1,":")+1,.)
replace v1 = subinstr(v1,`"""',"",.)
replace v1 = trim(v1)
local theNewText = v1 in 1
return local text = "`theNewText'"
}
end
**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment