i18next

Integration published by Jovo | 5,561 downloads

Store and manage multilingual responses (standard integration)

i18next CMS Integration

In this section, you will learn how to build voice applications that support multiple languages.

Introduction to i18n

i18n works by separating the content (the text/speech) from the application logic, to make it easier to switch languages.

Jovo uses a package called i18next to support multilanguage voice apps. You can find all relevant information here: i18next Documentation.

Configuration

Standard Configuration

The easiest way to configure i18n is to use the built-in functionality that requires a separate folder for all language resources:

Jovo Folder Structure i18n

To get started, create a folder called i18n in /app and add the languageResources using the locale ID (e.g. en-US.json, de-DE.json, en-GB.json, etc.). The file structure should look like this:

You can find out more about how these files are structured here: i18next Essentials.

If you follow these conventions, there is no need to additionally add anything to your app configuration.

Alternative File Paths

If you want to add files from a different path, you can do so in your config.js file:

For example, it could look like this:

Also possible:

i18next Configuration Options

You can also add additional configurations that are available for i18next. Those can be added like this:

You can find a list of i18next configuration options here.

Accessing the Content

In your app logic, you can then use this.t('key') to access the right string. It is also possible to use parameters with this.t('key', {parameter: 'value'}).

Here is some example code for the languageResources object above:

You can also use it with ready-made speechBuilder object:

Or by creating a new SpeechBuilder object, like so:

Advanced i18n Features

Jovo offers advanced i18n features that are specifically built for voice and conversational interfaces:

Randomized Output

If you're using the SpeechBuilder, you can also use arrays inside your languageResources for randomized output.

For this, returnObjects config for i18next needs to be enabled (default since Jovo Framework v1.0.0).

For example, your languageResources could look like this:

If you're then using a speechBuilder instance, it will use this array to add variety by returning randomized output:

So, without changing any of the code in your handlers, you can vary your output by simply adding new elements to your languageResources.

Platform-specific Responses

Since Jovo v2.1.4, we support platform-specific responses for i18n, as well as for CMS. This feature uses the app type (e.g. AlexaSkill, GoogleAction) as i18n namespace:

Adding namespaces like below to your language resources allows you to have isolated output for a specified platform, without altering the default one or updarting the code logic.

In this example, the value for goodbye will be overwritten, whenever a response is triggered by Alexa. welcome remains the same for all platforms.

If you don't want any output for a specific platform, use /.

CMS Integrations

You can also use these i18n features with the Jovo CMS Integrations like Google Sheets and Airtable.

i18next Changelog

Current version might be higher than the latest changes displayed below because of updates of dependencies.

3.0.11 (2020-04-06)

  • Updated Typescript to 3.8.x
  • Updated Prettier to 2.x

Committers: 2

2.x

Find the 2.x changelog here.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.