Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Doc: Missing Translations

Eli Dupuis edited this page Jan 17, 2017 · 3 revisions

Missing translations

When t is called with a nonexistent key, it returns the result of calling util:i18n/missing-message with the key and the context as arguments. The default behavior is to return "Missing translation: [key]", but you can customize this by overriding the function. The below example spits out the key along with the values of any arguments that were passed:

// app/utils/i18n/missing-message.js:

export default function(locale, key, context) {
  var values = Object.keys(context).map(function(key) { return context[key]; });
  return key + ': ' + (values.join(', '));
}

// Elsewhere:

t('nothing.here', { arg1: 'foo', arg2: 'bar' });
// => "nothing.here: foo, bar"

When a missing translation is encountered, a missing event is also triggered on the i18n service, with the key and the context as arguments. You can use this to execute other missing-translation behavior such as logging the key somewhere.

i18n.on('missing', function(locale, key, context) {
  Ember.Logger.warn("Missing translation: " + key);
});