angular - Ngx-translate setTraslation 在动态组件中缺少翻译
问题描述
我想加载定义自己的翻译的动态组件,但仍使用 TranslateService 的相同实例,以便全局语言更改事件到达动态组件。
我正在运行一个我认为是错误的问题,请参阅此 stackblitz 进行复制:https ://stackblitz.com/edit/github-1ujje5
以及 github 上的相关问题:https ://github.com/ngx-translate/core/issues/834
任何建议如何解决这个问题?
解决方案
发生这种情况是因为来自 http 请求的翻译覆盖了动态组件中设置的翻译。https://github.com/alexzuza在链接的 github 问题中提供的答案。
this.translate.getTranslation('en').pipe(take(1)).subscribe(() => {
this.translate.setTranslation('en', {
'DYNAMIC': 'I am dynamic component'
}, true);
});
推荐阅读
- angular - 在窗口滚动primeNg下拉菜单列表应该关闭
- reactjs - 我在几分之一秒内看到登录页面,然后被重定向到潜在客户表单
- ios - GoogleWebRTC 的 RTCEAGLVideoView 没有显示远程视频,而远程音频很好
- python - 为什么 SymPy 不真正计算这样的积分?
- python - 在 Python 中格式化 JSON GET 结果
- php - php购物车会话不更新属性,只更新数量
- c++ - MFC - 带有可选复选框的 CListCtrl 行
- mongodb - 总是产生相同哈希的无序 2 字符串哈希函数
- html - 表单提交响应上的 CSS 显示/隐藏 div
- python - 无法使用 Python Selenium Chrome Ubuntu 20.04 下载任何内容