我想在前端使用 ngx-translate 在应用程序加载时动态加载翻译。
我的后端返回 JSON 格式的响应,例如:
{
"something: "something"
}
我想在我的 TranslateLoader 上使用该输出而不是本地的en.json
file.
有什么办法可以实现这一点吗?
TL;DL:我想打电话'http://localhost:xxxx/api/translation/EN' 获取翻译的 JSON 响应并将其加载TranslateHttpLoader
您可以创建一个工厂:
export function httpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "http://localhost:xxxx/api/translation/", "");
}
并在 @NgModule 导入中使用它:
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: httpLoaderFactory,
deps: [HttpClient]
}
}),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)