You are currently viewing Dialogflow 8 – How to add a second language to our bot

Dialogflow 8 – How to add a second language to our bot


In this post we are going to see how to create an agent with several languages in Dialogflow. To avoid rewriting basic stuff I’m just copying here the link to the official docs on how to add and additional language and configure the intents:

Take a look the text box above … try to minimize your work as much as possible.

Once you have your second language you need to redefine the answers and training phrases for all the intents:

And now the fun part … What happens with our fulfillments? You will have to reprogram them to answer in two languages. If you have followed the best practice of separating the texts in constants out of the code, or even in a configuration file, it would be much easier, as you will need to update in a single point.

In  this example you have the option to keep external files for the texts. In our case I took the decisión to keep the text in the cloud function code and an external data base. To manage which language your agent is called from you need to read the properties agent.locale. In our Hotels Martinez example I have defined a language code in order to work with matrices:

if (agent.locale === ‘en-us’) { langcode=1 } else langcode=0;

With this, if the agent is called in American English it will get a langcode of 1, and 0 otherwise, which is Spanish for us.

Each text constant is defined as matrix as you can see in the following example:

An the code to provide the answer in our agent would be something like this:


For the data that we read from the external database we can use the same matrix idea, adding the langcode extraction to the function reading the database. In our case we only added a second language to the description of the hotel. Be careful on how a matrix of strings is defined in Datastore:

One last comment, the line to define the langcode must be in each fulfillment function in order to get a value in every intent invocation.



I work for Google Cloud, but this post are personal ideas and opinions

This Post Has 2 Comments

  1. Cavin Mugarura

    what id the language is not among the ones available by dialogflow

    1. jamarmu


      I’m afraid that if the language is not there you can’t use the tool … there should be a roadmap for new languages.



Leave a Reply