Locales

Introduction

EJS uses the concept of locales to represent a language and region combination. This allows for nuanced support for multiple dialects of a common language (such as American English vs Canadian English).

Locale codes

Each locale is represented by a locale code: a lowercase language code and an uppercase country code, separated by a hyphen (e.g. en-US for American English).

Supported locales

The following locales are currently supported. You may define other locales in your module, but the application will not be able to load them at this time.

  • en-US: English - United States

  • en-CA: English - Canada

  • fr-CA: French - Canada

  • es-ES: Spanish - Spain

Additional locales will be added in each release.

Active locale

The active locale determines which language packs are loaded and applied. When the active locale is changed, the associated language pack from the active module will be loaded and applied.

Changing the active locale

From inside a component, you may use the $setLocale instance method to change the active locale.

MyComponent.vue
<template>
    <button @click="$setLocale('fr-CA')">fr-CA</button>
</template>

<script>
    module.exports = {
        name: 'my-component',
        mounted() {
            this.$setLocale('fr-CA');
        }
    };
</script>

Default locale

An application must also specify a default locale. If an active locale has not been specified, the default locale will become the active locale.

When performing a translation, if a string is not available for the active locale, the translator will attempt to locate the string for the default locale as a fall-back. If the string isn't found in either the active or default locale, the resource identifier is returned.

Missing translation warnings

If the i18n-warnings flag has been enabled, a console warning will be issued for a missing string in the active locale, and an error if the string is also missing from the default locale.

Last updated