Last active
August 3, 2017 04:47
-
-
Save jazzedge/df956088af78141f5068c746aaab4103 to your computer and use it in GitHub Desktop.
Bot - Localization #3 load JSON file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) | |
| .title('welcome_title') | |
| .subtitle('welcome_subtitle') | |
| .images([ | |
| new builder.CardImage(session) | |
| .url('https://placeholdit.imgix.net/~text?txtsize=56&txt=Contoso%20Flowers&w=640&h=330') | |
| .alt('contoso_flowers') | |
| ]); | |
| session.send(new builder.Message(session) | |
| .addAttachment(welcomeCard)); | |
| // 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) | |
| .text(messageText); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment