The Mobile & Digital Assistant Blog covers the latest in mobile and conversational AI development and engagement

TechExchange: A Simple Guide and Solution to Using Resource Bundles in Custom Components

Frank Nimphius
Master Principal Product Manager

Sample by Frank Nimphius, March 2018

A common requirement for bots is to support multiple languages. To address this requirement, Oracle Intelligent Bots provides the ability to configure translation services from Google and Microsoft to auto-translate user input messages and bot responses. If you don't want bot responses to be auto-translated then a second option is to use Resource Bundles instead.

All the before mentioned options work great for building multi lingual bots, but require messages to be defined in the dialog flow, or saved in context variables. This excludes custom components that directly write user responses to the message channel using the bot SDK conversation.reply( … ) function.

Without going into a longer discussion of when custom components should write message responses directly to a message channel and when they should save messages or data in a context variable, we simply accept the fact that there are use cases for custom components to be self-contained. This however then bears the question of how to implement translations for those responses.

To translate bot responses sent directly from a custom component, you have two options

  • Call a translation service from the custom component implementation code before sending a message. This option is suitable if the messages are not composed in the custom component but queried from a remote backend. Here auto-translation will help making the strings available in the bot user preferred language.
  • Use message bundles to provide translated responses for the languages you want the bot to support. Message bundles can use placeholders in the translated strings for the custom component to insert data value at runtime. Message bundles in custom components are a viable option if the custom component queries data from a remote service to integrate in a bot response.

The article (readme), and its sample, shows a simple solution to implement message bundle support in custom components. You can leverage the sample sources in your own custom component projects, and the readme in the sample tells you how. 


The image above shows the sample at runtime. When a German string is issued, then the custom component response is in German. If French, then the response is in French (well, you get the idea)


Update note:

Oracle Intelligent Bots has been rebranded Oracle Digital Assistant to better describe its capabilities beyond a standard chatbot. To learn more, visit cloud.oracle.com/digital-assistant

A Simple Solution to Using Resource Bundles in Custom Components (ZIP)

Join the discussion

Comments ( 3 )
  • Srikanth Ramineni Wednesday, August 29, 2018
    Hi Frank,
    I tried this approach and it works great. Thanks a lot for this documentation.
    I see one minor bug though.
    In messageBundle.js file, I see startPos = indx + 3.
    So in second iteration, for next index of '{', it starts searching after 3 more positions.
    This will not work when you replace your token with a string less than 3 characters and you have an immediate token after it.

    For Ex:
    Your salary is {0}{1} per {2}.
    initial index = 15 (for {0}).
    After Replacing first token with currency symbol:
    Your salary is ${1} per {2}.
    new initial index with (startPos = indx + 3) will be 18
    This will skip the second token because of the 3 increment we are doing.

    To fix this, may be we can have startPos = indx instead;

    Srikanth R
  • Fran Nimphius Wednesday, August 29, 2018
    Thanks for pointing out. I'll have a look. Meanwhile, feel free to take the code and make it yours, and create a modified version

  • Wim Monday, March 11, 2019
    Another small bug and for future reference;
    When your string starts directly with a replacement ex.:
    {0} has uploaded a document

    Then it won't work. Change:
    while (indx > 0) {
    while (indx > -1) {
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.