我正在尝试在 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
}
})
网页:
{{'MOJO'|translate}} //this return only DEMO, not DEMO|compiled