I have all configuration and setting following instructions.
app.module.ts
import { Http } from '@angular/http';
import {TranslateModule, TranslateStaticLoader, TranslateLoader, TranslateService } from 'ng2-translate';
imports: [
BrowserModule,
HttpModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
deps: [Http]
})
]
Component:
import {TranslateService,TranslatePipe } from 'ng2-translate';
constructor( private activateRoute: ActivatedRoute, public translate: TranslateService) {
translate.addLangs(['en']);
translate.setDefaultLang('en');
}
And view component:
{{ 'Intro' | translate }}
This library does not work for me, it alwsays displays key of word Intro
instead value translations.
There are not any errors in console. Why ngx-translate
does not work or what I do wrong.
if you're still on Angular <4.3, please use Http from @angular/http with http-loader@0.1.0.
so running
did the trick for me
Source: ngx-translate/core
Looking at your code can't really tell what's not working. One difference I noticed is, I did my setup using
HttpLoaderFactory
provided byngx-translate
doc. I'll provide my full setup and you can compare it with your code, if it helps to detect any issues :)Setup:
app.module.ts:
src > assets > i18n > en.json:
component.ts:
component.html: