Kogno
  • Introduction
  • Getting Started
    • Configuration
    • Starting the Server
    • Messenger Configuration
    • Telegram Configuration
    • WhatsApp Configuration
    • NLP Configuration
  • Conversation Class
  • Contexts
    • Blocks
      • before_anything
      • postback
      • deep_link
      • command
      • any_attachment
      • regular_expression
      • keyword
      • any_number
      • any_text
      • intent
      • entity
      • membership
      • recurring_notification
      • everything_else
      • after_all
    • Sub Contexts
    • Routing
    • Sequences
    • Conversational Forms
  • Replies / Notifications
    • text
    • button
    • quick_reply
    • raw
    • list
    • carousel
    • url
    • typing
    • image
    • video
    • html
    • markdown
    • contact
    • location
    • recurring_notification_request
    • messenger_generic_template
    • whatsapp_template
  • Templates
  • Models
    • User model
  • Scheduled Messages
  • Telegram Inline Query
  • Command Line
  • Global Methods
  • Internationalization
Powered by GitBook
On this page
  • Configuration
  • Default locale
  • Setup locales
  • Examples
  • Usage
  • t(key=String|Symbol, **interpolation)
  • Example
  • User Locale

Was this helpful?

Internationalization

The I18n library is already integrated in Kogno, so the development of a multi-language chatbot is relatively easy.

PreviousGlobal Methods

Last updated 2 years ago

Was this helpful?

Configuration

Default locale

The default locale can be set editing the configuration config.default_locale in file.

Setup locales

Kogno will load automatically all .yml files located in the folder config/locales/ .

All necessary locales files can be created. Being one for each language supported by the chatbot.

Examples

English: config/locales/en.yml

en:
  hello:
    - "Hello"
    - "Hi"
  hello_name:
    "Hello %{name}!"

  goodbye:
    "Goodbye πŸ‘‹"

Spanish: config/locales/es.yml

es:
  hello:
    - "Hola!"
    - "Β‘Hola! πŸ˜ƒ"
    
  hello_name:
    "Hola %{name}!"

  goodbye:
    "Adios πŸ‘‹"    

If in value there is more than one option, like in the example above, hello with options "Hello" and "Hi", Kogno will randomly return a single one.

This would help create a less monotonous conversation.

Usage

The global method t() (short for I18n.t()) can be called anywhere in a project's code.

t(key=String|Symbol, **interpolation)

Example

class MainContext < Conversation
  
  def actions

    intent :gretting do
    
      if @user.first_name.nil?
        @reply.text t(:hello)
      else
        @reply.text t(:hello_name, first_name: @user.first_name)
      end
      
    end

    intent :bye do
    
      @reply.text t(:goodbye)
      
    end

  end

end

User Locale

But this can be changed by calling the set_locale() from User model.

@user.set_locale(:es)

Read more examples of I18n usage in the .

By default, the locale of a user starting a conversation for first time will be the one defined in the , if the platform has not included it in the webhook.

official documentation
config/application.rb
chatbot settings