Skip to content

Instantly share code, notes, and snippets.

@bbdaniels

bbdaniels/gtrans.ado

Created Jan 21, 2021
Embed
What would you like to do?
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