Project process – Things got into shape, and I finally know to appreciate REST APIs

Language Translator from IBM Cloud

Language Translator

The project has finally gotten into shape! Last time I wrote that I wanted to include a translation by google translate in my web application, it turned out Google charge quite a bit for the Google Translate API, so I turned for other free service and found Language Translator from IBM Cloud. It allows free translator of 1,000,000 characters per month and is enough for development purpose.

latest screenshot of the web application

Product Layout

Now this web application is divided into four sections ( excluding the button ):

Left-Top section: Source text provided by user

Middle Top section: A tokenized version of the source text by part-of-speech. Access by a REST API written with Flask.

Rightmost section: A list of words translated by a free Japanese-English dictionary JMdict.

Lower section: A large textarea which hold the translation result by IBM Cloud Language Translator.

Product Functions

  • Tokenize Japanese text according to its part-of-speech, which are estimate by MeCab
  • If mouse over a tokenized word, the tooltip would show part-of-speech
  • Provide dictionary result of the words
  • Provide real translation by translation service

 

Now I am not going to make it prettier just for the sake of it. I have to ready the production environment and how to ship it. Also I have to wrap my REST API with HTTPs and make sure no one could access it except my server.

To be honest, the Language Translator API sucks

IBM Cloud provided four ways to access its Language Translator, they are: curl, Node, Java and Python. Ideally I would have chosen the Python way to access it. However, it requires Visual C++ Framework 14.0 and I would have to download Gigabytes of data just to install the Visual Studio Community 2017 which contains Visual C++ compiler. To be honest, I hate Microsoft stuff with passion because of the horrible experience with coding Visual Basic.

Since it is a Python project, I don’t want to mix it with Java or NodeJS. The last option is an ugly Curl API like this:

curl --user apikey:{apikey_value} --request POST --header "Content-Type: application/json" --data "{\"text\": [\"Hello, world!\", \"How are you?\"], \"model_id\":\"en-es\"}" https://gateway.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01

It has to use slashes ( ‘\’ ) to escape the double quotes ( ” ) in order to send a JSON over curl data. And in order to use this in a Python Program, not only do I have to Use Python Subprocess to call external program “curl”, I have to escape the slashes one more time with a double slash ( \\\ )

“curl –user apikey:XXXXXXXXXXXXXXXXXXXXXXXXXXXX –request POST –header \”Content-Type: application/json; charset=UTF-8\” –data \”{\\\”text\\\”:[\\\”” + text +”\\\”],\\\”model_id\\\”:\\\”ja-en\\\”}\” \”https://gateway-syd.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01\””

 

Man this is ugly, but it comes with free service. Now I finally understand why REST API is a thing. You don’t need to install anything, you just send a request over HTTP and it magically return something to you!

Leave a Reply

Your email address will not be published. Required fields are marked *