Reputation: 51
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
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