i18n Helpers

Table of Contents

i18n

{{i18n}}

Looks up a translation key for the current language. The helper expects a language (or lang) property in the context, along with an object containing translations for that language.

Params

  • key {String}: The translation key to look up (supports dot notation for nested keys)
  • returns {String}: The translated string

Example

Given the following context:

{
      language: 'en',
      en: {
        greeting: 'Hello',
        messages: {
          welcome: 'Welcome to our site'
        }
      },
      es: {
        greeting: 'Hola',
        messages: {
          welcome: 'Bienvenido a nuestro sitio'
        }
      }
    }
    
{{i18n "greeting"}}
    
    
    {{i18n "messages.welcome"}}
    
    

To switch languages, change the language property in the context:

{
      language: 'es',
      // ... translations
    }
    
{{i18n "greeting"}}
    
    

Notes

  • The helper throws an error if the key parameter is not a string
  • The helper throws an error if language or lang is not set or is not a string
  • The helper throws an error if the language object is not found in the context
  • The helper throws an error if the translation key is not found

Table of Contents