πŸ“ƒ
NewBot
  • NewBot, what is it?
  • ConverseScript Syntax
    • Variables
    • Arithmetic
    • Boolean
    • Array and object
    • Entering text and output
    • Magic variables
    • Condition
    • Loop
    • Functions
    • The decorators
      • Use @Condition
      • Use @Action
      • Use @Format
      • Use @Intent
      • Use @Event
  • Prebuilt Formats for Widget
    • Quick Replies
    • Multi Cards
    • Articles
    • Form
  • Pre-built function for the widget
    • Request()
    • Map()
    • _ (lodash)
  • Get Started with Framework
    • Install
    • Main Skill
    • Write the conversational script
  • Use NewBot Framework JS
    • Create a skill (more details)
      • Relationship between skills
      • Use the functions of a child competency
      • Conditional
      • Control access to a skill
    • Create a JavaScript function and trigger it in ConverseScript
    • The constants
    • Write formats
      • Write and use multi-formats
      • Share formats
    • Internationalization (i18n)
    • Set up an NLP system
      • Share the NLP system
      • Use DialogFlow
    • Deploy on the browser
    • Run the chatbot on NodeJS
    • Send data when running the chatbot
    • The middlewares
    • Save the user's progress
    • User object
  • Unit Tests
    • Test a scenario
    • Test variables
    • Spy a function
    • Create a mock
    • Test the events
    • Test the actions
Powered by GitBook
On this page
  • In a string
  • With parameters
  • Ask the language

Was this helpful?

  1. Use NewBot Framework JS

Internationalization (i18n)

To have multiple languages, let's create an languages folder with multiple JSON files:

en_EN.json:

[
    {
        "hello": "hello"
    }
]

fr_FR.json:

[
    {
        "hello": "salut"
    }
]

Let's create an languages/index.js file

import fr_FR from './fr_FR.json'
import en_EN from './en_EN.json'

export default {
    packages: { en_EN, fr_FR }
}

In the main.js file, import the languages ​​and assign them to the languages property:

import code from './main.converse'
import languages from './languages'

export default {
   code,
   languages
}

In the main.converse scenario:

@Event('start')
start() {
    > hello
}

Depending on the language of the user, it will show "Hello" or "Hi"

On the browser side, the default language is the browser language

In a string

Let's put the symbol # before the text. Example:

@Event('start')
start() {
    myvar = '#hello'
}

With parameters

If the JSON is:

en_EN.json:

[
    {
        "nb message": "you have %d message%p"
    }, 
    {
        "plurial": {
            "p": [
                "s"
            ]
        }
    }
]

The goal is to display the plural according to the number of messages. To add parameters, put a table at the end of the line:

@Event('start')
start() {
    nb = 1
    > nb message [3] // You have 3 messages
    > nb message [nb] // You have 1 message
}

Ask the language

It is possible to assign a language to the user. Why not make a dialogue that asks for language?

@Event('start')
start() {
    Lang.set('fr_FR') // change language
    > Your language : { Lang.name() }
}
PreviousShare formatsNextSet up an NLP system

Last updated 3 years ago

Was this helpful?

Go further The language system is based on Languages.js. You can consult the documentation on

https://languages.js.org