Translating between languages with Language Translator
To start, provision a new Language Translator service instance. Once that's done, head over to your favorite text editor, open up a new Python file, and let's get coding:
- Import the service:
from watson_developer_cloud import LanguageTranslatorV3
- Initialize the API:
language_translator = LanguageTranslatorV3(version=“2018-05-01”, iam_apikey=“rvE894AVGJQ_t_ZNuUoQrclWWQwvpFB0_78jr9pvtjIl”)
Of course, you should use your own API Key.
- We just need to translate and get our result! But let's make it a bit prettier, and create a command-line interface for it:
print “Enter a sentence in English:” eng_sent = raw_input() translation = language_translator.translate(text=eng_sent, model_id=“en-fr”).get_result()[“translations”][0][“translation”] print “Your sentence in French is:\n” + translation
- Run your code, and let's see some output:
Enter a sentence in English: My name is Frank Felix Your sentence in French is: Je m'appelle Frank Felix Enter a sentence...