My project is set up with Angular CLI, so it's built with webpack but the webpack config files are hidden.
I got two files, nl.json
and fr.json
, but get a 404
for both, even though it looks like it's going to the correct folder: http://localhost:4200/i18n/nl.json
.
They have this structure:
{
"SEARCH_PAGE": {
"searchPerson": "Zoek een persoon",
"search": "Zoek"
}
}
In app.module
:
...
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [Http]
}
}),
...
and
export function HttpLoaderFactory(http: Http) {
return new TranslateHttpLoader(http, "/i18n/", ".json");
}
I also include these in my sub module where I [try to] use the translation, with the difference of .forChild
instead of .forRoot
.
In my component:
constructor(translate: TranslateService) {
translate.addLangs(["nl", "fr"]);
translate.setDefaultLang('nl'); // this language will be used as a fallback when a translation isn't found in the current language
let browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/nl|fr/) ? browserLang : 'nl');
}
Could it be something not linked to ngx-translate
?
When I use the pipe <h1>{{ 'SEARCH_PAGE.searchPerson' | translate}}</h1>
I get nothing on the screen, when I use the directive <h1 translate]="'SEARCH_PAGE.searchPerson'"></h1>
I get literally the string.
web.config
file fixes the issue. – Askwith