4

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?

1 Answers1

0

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];
  }

}
Rick Barkhouse
  • 1,186
  • 2
  • 10
  • 15