dojo dragon main logo

Standalone API

Accessing locale message bundles

Once a default language bundle has been imported, any locale-specific messages are accessed by passing the message bundle to the i18n function.

For example:

import { localizeBundle } from '@dojo/framework/i18n/i18n';
import bundle from 'nls/main';

localizeBundle(bundle, { locale: 'fr' }).then(({ messages }) => {
    console.log(messages.hello); // "Bonjour"
    console.log(messages.goodbye); // "Au revoir"

If an unsupported locale is passed to i18n, then the default messages are returned. Further, any messages not provided by the locale-specific bundle will also fall back to their defaults. As such, the default bundle should contain all message keys used by any of the locale-specific bundles.

Determining the current locale

@dojo/framework/i18n/i18n exposes two related methods for determining the current locale:

  • getCurrentLocale, which represents the application's current, top-level locale.
  • getComputedLocale, which will be either the user's system locale if it is listed among the supported locales specified in the .dojorc, or the default locale specified in the .dojorc if the user's system locale is not supported.