How many languages can you speak (sorry, fellow geeks; I mean human languages, not programming)?
Every day people across the globe depend more and more on the Internet for their day-to-day activities, increasing the need for software to support multiple languages to accommodate the growing diversity of its users. If you work developing software, this means it is only a matter of time before you get tasked to translate your applications.
Wouldn't it be great if you could learn something with just a few key strokes? Just like Neo in The Matrix when he learns kung fu. Well, wish no more! I'll show you how to teach your applications to speak in multiple languages with just a few key strokes using Watson’s Language Translation service, available through Bluemix. It provides on-the-fly translation between many languages. You pay only for what you use and it’s consumable through web services, which means pretty much any application can connect to it—and it's platform and technology agnostic!
I'll show you how easy it is to create a PHP program with language translation capabilities using Watson's service.
Step 1: The client.
You can write your own code to interact with Watson’s Translation API, but why should you? The work is already done for you. You can pull in the client via Composer, the de-facto dependency manager for PHP. Make sure you have Composer installed, then create a composer.json file with the following contents:
We will now ask Composer to install our dependency. Execute one of the following commands from your CLI:
After the command finishes, you should have a 'vendor' directory created.
Step 2: The credentials.
Step 3: Put everything together.
At the same level where the composer.json file was created in Step 1, create a PHP file named test.php with the following contents:
Save the file, buckle up, and execute it from the command line:
Voilà! Your application now speaks French!
Explore other languages Watson knows and other cool features available through Watson's Language Translation service.