ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.51k stars 575 forks source link

Not working with "@angular-devkit/build-angular": "0.8.*" #922

Open skorunka opened 6 years ago

skorunka commented 6 years ago

The translations stop silently working after upgrading @angular-devkit/build-angular from 0.7.5 to 0.8.0 or 0.8.1. There is no error in the console or anywhere. Beta versions 0.9.0-beta.1 and ^0.9.0-beta.2 do not work as well.

gochi-dot commented 6 years ago

I have the same error

skorunka commented 6 years ago

Same problem with 0.8.2.

Dlacreme commented 6 years ago

Same problem here. No errors nor warnings. v 0.8.2

gerardcarbo commented 6 years ago

In my case I've solved the problem specifying the default property of the imported json (ie. enUS.default):

import * as enUS from '../../../translations/en-US.json';
....

@Injectable()
export class I18nService {

  defaultLanguage: string;
  supportedLanguages: string[];

  constructor(private translateService: TranslateService) {
    translateService.setTranslation('en-US', enUS.default);
    ....
skorunka commented 6 years ago

Can confirm @gerardcarbo solution works. Thank you.

peterpeterparker commented 5 years ago

thx @gerardcarbo, your solution worked for me too

if that could help someone else, if you load many languages, like me fr/de/it/en, you have to do the tricks for each of your languages

For example:

    this.translateService.addLangs(['en', 'de', 'fr', 'it']);
    this.translateService.setDefaultLang('en');

    this.translateService.setTranslation('en', translationEn.default);
    this.translateService.setTranslation('fr', translationFr.default);
    this.translateService.setTranslation('it', translationIt.default);
    this.translateService.setTranslation('de', translationDe.default);