SAP|SAP Spartacus internationalization ( i18n ) 翻译问题的排错指南
有 partners 在使用 SAP Spartacus 进行二次开发时,遇到这个警告消息:Translation key missing 'common.search' in the chunk 'common' in file spartacus-core.js
看我的解答:
Hi there,
if you would like to use cxTranslate pipe, make sure you import I18nModule from @spartacus/core and add it in the import section of your AppModule:
文章图片
Here below is tips about trouble shooting i18n issues.
In my app.module.ts I use B2cStorefrontModule.withConfig to pass my application specific configuration. In Chrome Development Tool, I set breakpoint on line 82:
文章图片
then in the runtime when the breakpoint is triggered, you can check in debugger, to inspect whether a given translation key, like "common.search" in your case exsts or not. If not exist, you will meet with error message mentioned in this thread.
文章图片
I am testing based on Spartacus version 2.1 and I didn't find there is translation key "search" under common chunks, as see in highlighted area above.
【SAP|SAP Spartacus internationalization ( i18n ) 翻译问题的排错指南】I just manually added a custom translation key via:
function provideAdditionaLanguage(translations: TranslationResources) {
translations["en"].common.common.jerrysearch = "Jerry Search";
return translations;
}
and configure it in AppModule below:
文章图片
Then consume it in my page:
文章图片
final result,it works:
文章图片
更多Jerry的原创文章,尽在:"汪子熙":
文章图片
推荐阅读
- csapp之lab(shell lab)
- csapp之第8章(异常控制流)
- 如何在浏览器里开发并运行|如何在浏览器里开发并运行 SAP UI5 应用
- SAP|SAP UI5 初学者教程之十七 - 聚合绑定在 UI5 复合控件中的使用试读版
- 什么是|什么是 SAP HANA XS JavaScript
- SAP|SAP UI5 初学者教程之十五 - 对话框和 Fragments 的使用方式
- SAP|SAP UI5 初学者教程之十四 - 嵌入视图的使用方式试读版
- OSA|OSA 安装
- 【合集】Jerry|【合集】Jerry Wang 2018~2021 四年期间的 SAP 技术文章合集
- SAP|SAP 电商云 Spartacus UI 的响应式 UI 实现细节