Add the Watson service

You now have your shell application and can add the Watson service.

    1. In Bluemix, add or bind the Watson Language Translation service. You don’t need to restart the application for now.

      Now, you see the service credentials.


    1. In the file, import the language translation component from the watson_developer_cloud SDK:# -*- coding: utf-8 -*-from django.shortcuts import render

      from django import forms

      from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation

      from watson_developer_cloud import WatsonException

      import logging

      import json

      The final change is in the placeholder that you created in the file. Remember to use the service credentials that you got for Bluemix as the language translation user name and password.


    1. Open the file and find this code:if form.is_valid():   data = form.cleaned_data['txtdata']
"Text to be processed is %s " % data) 

         lang = "TBD"


         allinfo['lang'] = lang


  1. Add code that invokes the language detection service after the line lang = “TBD” and before the line allinfo[‘lang’] = lang:
    lang = "TBD"[Add code here]

    allinfo['lang'] = lang


        if form.is_valid():

          data = form.cleaned_data['txtdata']

"Text to be processed is %s " % data) 

          lang = "TBD"


            language_translation = LanguageTranslation(username='<user>',



            langsdetected = language_translation.identify(data)                                                          

  , indent=2)) 




            primarylang = langsdetected["languages"][0]['language']

            confidence = langsdetected["languages"][0]['confidence']


            lang = "I am %s confident that it is %s" % (confidence, primarylang)

          except WatsonException as err:

           allinfo['error'] = err;


          allinfo['lang'] = lang


          allinfo['error'] = "Form is invalid"