Mutlilingual bot (capturing user input and intercepting bot's output for translation)

You’ll need to build a Custom Pipeline Component (read more) that detects the language of the input.

You have 2 possibilities:

1. Understand and respond in only French and English:

Introduce intents with examples in both English and French.

- intent: greet
  examples: | 
  - hello
  - bonjour
etc...

Your Component will only detect the language only and save it.

All your responses will need to be Custom Actions; in which you access the language and dispatch the correct message accordingly:

if language == "fr":
    dispatcher.utter_message("Salut! Comment puis-je vous aider?")
    #/* or dispatcher.utter_message(response = "utter_greet_fr") */
else:
     dispatcher.utter_message("Hey! How can I help you?")
    #/* or dispatcher.utter_message(response = "utter_greet_en") */

UPDATE: You can now use Conditional Response Variations instead:

responses:
  utter_greet:
    - condition:
        - type: slot
          name: language
          value: fr
      text: "Salut! Comment puis-je vous aider?"
    - text: "Hey! How can I help you?"

2. Understand and respond in any language:

Introduce intents with examples in English only.

- intent: greet
  examples: | 
  - hello
  - hey there
etc...

Your Component will detect the language, save it, and then translate the user input into English before passing it to the rest of the Pipeline, which will therefore process the translated English text and match it to an intent.

All your responses will need to be Custom Actions; in which you access the language, and translate then dispatch the message accordingly:

english_text = translateEnglish("Hey! How can I help you?", language)
dispatcher.utter_message(english_text)
1 Like