demo Golang backend code for a Slack /slash command to translate text from one language to another. NOTE: this demo code is google appengine-specific. rip out those mini bits and you can run it anywhere.
i wrote this because i wanted 2x new /slash commands:
/e2j <english text> to translate English to Japanese
/j2e <japanese text> to translate Japanese to English
assuming slash command
/e2j has been setup in your slack as a new slash command to translate English to Japanese, you've pointed it to your appengine instance, if a user entered
/e2j the rain in spain falls mainly on the plane the response would be something like:
/j2e has been setup as above (but for Japanese to English), if a user entered
/j2e スペインの雨は、平面上に、主に落ちます the response would be something like:
the demo code as you see it here is only setup for English <--> Japanese, but you can see how easy it would be to tailor to your specific needs/reqs.
instructions are for English <--> Japanese
- the code as-is is for google app engine. create a new appengine app, do what you need to do
- get your google translate api key. follow the steps here: https://cloud.google.com/translate/v2/getting_started
- create your new /slash commands
/j2e. configure them to GET to the URIs
/translate/ja_enat the FQDN of your appengine app from step 1.
- change the appropriate values in
SLACK_VERIFY_TOKEN). make sure your application name is correct (etc)
$ go build && goapp deploy