Created
January 21, 2021 18:13
-
-
Save bbdaniels/9d8f6e0df0a7f444b027895914e6be6a to your computer and use it in GitHub Desktop.
Google Translate for Stata
This file contains hidden or 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
| ** | |
| 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