7/12/2017 - 6:56 AM

Bot - Localization #3 load JSON file

Bot - Localization #3 load JSON file

// https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/demo-ContosoFlowers/README.md

// The SDK also provides a way to configure the default bot's locale:

// Set default locale
bot.set('localizerSettings', {
    botLocalePath: './bot/locale',
    defaultLocale: 'en'

// Each file in the locale folder corresponds to a another file in the bot's dialogs folder. They contain the resource strings used by each dialog. 

// bot/locale/en/index.js
    "welcome_title": "Welcome to the Contoso Flowers",
    "welcome_subtitle": "These are the flowers you are looking for!",
    "contoso_flowers": "Contoso Flowers",
    "main_options_order_flowers": "Order flowers",
    "main_options_talk_to_support": "Talk to support",
    "main_options_settings": "Settings",
    "help": "Help",
    "thank_you": "Support will contact you shortly. Have a nice day :)"

// Send text:

bot.dialog('/', function (session) {
    session.send('welcome_title');              // Will print "Welcome to the Contoso Flowers"
    session.send('welcome_subtitle');           // Will print "These are the flowers you are looking for!"

// Send a card:

var welcomeCard = new builder.HeroCard(session)
        new builder.CardImage(session)

session.send(new builder.Message(session)

// Using the SDK to manually localize text
// You can also localize content by using session.gettext() method which returns a localized string using the session's preferred locale. This same method also supports template strings, where placeholders are replaced with the other arguments passed to the method. E.g:

// bot/locale/en/checkout.json
    "final_price": "The final price is $%d (including delivery). Pay securely using our payment provider.",

// bot/dialogs/checkout.js#L37
var messageText = session.gettext('final_price', order.selection.price);
var card = new builder.HeroCard(session)