Ngx翻译编译器,不编译

时间:2017-10-02 13:17:00

标签: javascript angular ngx-translate

我正在尝试在CustomCompiler中编译请求的响应,但我遇到了问题。编译数据后,我返回编译后的变量,但是当我使用翻译过滤器时,我仍然会看到旧的翻译文本。

我的装载机工厂和自定义编译器代码:

export function HttpLoaderFactory(http: HttpClient) {
 return new TranslateHttpLoader(http,'http://localhost:8100/getWebMultilanguages?lang=');
}

export class CustomCompiler implements TranslateCompiler{

  compile(a:string,b:string) {
    console.log('compile',a,b)
    return '{}';
  }

  compileTranslations(translation:any,b:string){
    return Object.keys(translation).reduce((acc: any, key) => {
      acc[key] = translation[key] + '|compiled';
      return acc;
    }, {});
    //return {MOJO:'DEMO'}
  }

}

翻译模块导入为:

TranslateModule.forRoot({
      loader: {
        provide:TranslateLoader,
        useFactory:HttpLoaderFactory,
        deps:[HttpClient]
      },
      compiler:{
        useClass:CustomCompiler,
        provide:TranslateCompiler
      }
    })

Html:

{{'MOJO'|translate}} //this return only DEMO, not DEMO|compiled

0 个答案:

没有答案