头图

SAP Spartacus internationalization ( i18n ) 翻译问题的排错指南

JerryWang_汪子熙

有 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.

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的原创文章,尽在:"汪子熙":

阅读 241

Jerry Wang的SAP技术专栏
SAP成都研究院开发专家,SAP社区导师,SAP中国技术大使

Jerry 2007年从电子科技大学计算机专业硕士毕业后进入SAP成都研究院工作至今, SAP社区导师,SAP中国技术...

781 声望
1k 粉丝
0 条评论

Jerry 2007年从电子科技大学计算机专业硕士毕业后进入SAP成都研究院工作至今, SAP社区导师,SAP中国技术...

781 声望
1k 粉丝
文章目录
宣传栏