我正在尝试在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