user1442058
user1442058

Reputation: 51

ng2-translate: Is there any way to use default lang in case of Missing Translations?

I am using angular2 rc5 and for i18n ng2-translate.

I want MissingTranslationHandler to automatically fall down to default language rather than providing explicit translations for missing values .

Is it possible to do in any way?

Upvotes: 4

Views: 772

Answers (1)

Rick Barkhouse
Rick Barkhouse

Reputation: 1206

I came up with the following solution, it's probably not the best, but it works. It simply looks up the message manually from the en.json file. I tried using params.translateService.currentLang and params.translateService.getDefaultLang() to implement this but they were always undefined for some reason :(

import { MissingTranslationHandler, MissingTranslationHandlerParams } from 'ng2-translate';

let enBundle = require('../../assets/data/i18n/en.json');

export class MyMissingTranslationHandler implements MissingTranslationHandler {

  handle(params: MissingTranslationHandlerParams) {
    return enBundle[params.key];
  }

}

Upvotes: 0

Related Questions