Kogno
Search…
⌃K

Internationalization

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

Configuration

Default locale

The default locale can be set editing the configuration config.default_locale in config/application.rb 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
Read more examples of I18n usage in the official documentation.

User Locale

By default, the locale of a user starting a conversation for first time will be the one defined in the chatbot settings, if the platform has not included it in the webhook.
But this can be changed by calling the set_locale() from User model.
@user.set_locale(:es)
Last modified 4mo ago