Angular 4 Ngx平移管道不起作用

fan*_*gio 5 html internationalization typescript ngx-translate angular

我想制作一个多语言的angular 4应用程序。我已经按照Angular 2-Multilingual Support的答案进行了操作, 但是它不起作用。

我做了每一步,从该页面上的1到5,我的appmodule看起来一样。

我在资产文件夹中的文件夹i18n中有一个文件en.json。该文件包含

{ "TEST":"little test"}
Run Code Online (Sandbox Code Playgroud)

在我的HTML中:

 <a [routerLink]="['/home']" class="tile waves-effect waves-light btn-large">
  <span> {{ "TEST" | translate }}</span>
 </a>
Run Code Online (Sandbox Code Playgroud)

当我使用它时,我得到的是测试而不是很少的测试。这真的很烦,因为我想添加多种语言。

编辑
我已将此代码添加到我的appmodule.ts中(仅添加了必要内容)

import {HttpClientModule, HttpClient} from '@angular/common/http';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

@NgModule({
  imports: [
    BrowserModule,
    HttpModule,
    HttpClientModule,
    MaterializeModule.forRoot(),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }),
    FormsModule,
    JsonpModule,
    routing,
    BrowserAnimationsModule,
  ],
Run Code Online (Sandbox Code Playgroud)

项目结构

k11*_*1k2 6

你可以这样试试吗?

export function HttpLoaderFactory(http: Http) { return new TranslateHttpLoader(http, "./assets/i18n/", ".json"); }