Ng2-translate: Is there a way to use default lang if there are no translations?

I use angular2 rc5 and for i18n ng2-translate.

I want the MissingTranslationHandler to automatically fall into the default language, and not provide explicit translations for missing values.

Can this be done in any way?

+4
source share
1 answer

I came up with the following solution, it is probably not the best, but it works. It just searches for the message manually from the en.json file. I tried to use params.translateService.currentLangit params.translateService.getDefaultLang()for implementation, but they were always undefinedfor 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];
  }

}
0
source

Source: https://habr.com/ru/post/1653418/


All Articles