Expand my Community achievements bar.

SOLVED

Load Site Specific Dictionary

Avatar

Level 5

Hi, 

 

We have dictionary under /content/dam for languages say (en-us, es-us) . When we load the page its injected and we have the translated content render on the page. As part of the requirement I have some doubts to clarify.

 

1) When I load the page, I see multiple calls of /libs/cq/i18n/dict.xxx.json, how can we restrict default dictionary calls?

  • /libs/cq/i18n/dict.en.json
  • /libs/cq/i18n/dict.en-US.json (We need only this one)
  • /libs/cq/i18n/dict.en.json

2) My custom dictionary /libs/cq/i18n/dict.en-US.json has only 5 labels, but in response i see numbers of other labels may be injected via /libs/cq/i18n/dict.en.json

 

3) Is there way to load /libs/cq/i18n/dict.en-US.json as per site level. Say, I want to load the dictionary on /content/mySiteA/en-US and not on /content/mySiteB/en-US ? keeping in consideration that codebase is same.

 

Thanks,

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vdhim23,

i18n dictionaries are retrieved using call to Servlet(com.adobe.granite.i18n.impl.ResourceBundleExportServlet) registered with path /libs/cq/i18n/dict being called via xhr request from JS.

In particular, it is the clientlib with category named granite.utils -> source -> I18n.js which has desired logic.

For your queries:

  • Multiple calls 
    • In Network trace, observe the "Initiator" of all the request to above path(each and every dict request's initiator to be observed) and see from which clientlibs it is triggered (Eg. for we-retail pages, granite.utils is added as one of the dependencies in clientlib-depencies category - /apps/weretail/clientlibs/clientlib-dependencies)
    • Remove additional ones based on the need
  • Locale and URL precedence and from where it is retrieved is clearly mentioned in below JS. I suggest to walk through this JS and use it per your expected flow 
    • /libs/clientlibs/granite/utils/source/I18n.js

With above 2 pointers, you will be able to make a call to the servlet/set locale per your need.(for content specific call)

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @vdhim23,

i18n dictionaries are retrieved using call to Servlet(com.adobe.granite.i18n.impl.ResourceBundleExportServlet) registered with path /libs/cq/i18n/dict being called via xhr request from JS.

In particular, it is the clientlib with category named granite.utils -> source -> I18n.js which has desired logic.

For your queries:

  • Multiple calls 
    • In Network trace, observe the "Initiator" of all the request to above path(each and every dict request's initiator to be observed) and see from which clientlibs it is triggered (Eg. for we-retail pages, granite.utils is added as one of the dependencies in clientlib-depencies category - /apps/weretail/clientlibs/clientlib-dependencies)
    • Remove additional ones based on the need
  • Locale and URL precedence and from where it is retrieved is clearly mentioned in below JS. I suggest to walk through this JS and use it per your expected flow 
    • /libs/clientlibs/granite/utils/source/I18n.js

With above 2 pointers, you will be able to make a call to the servlet/set locale per your need.(for content specific call)

Avatar

Level 4

Thanks. But I think this would still not solve the requirement of being able to load site specific i18n JSON. Is there any alternative to writing a custom servlet? 

/apps/proj1/i18n/en.json > has 100 keys and messages

/apps/proj2/i18n/en.json > has 100 keys and messages

/apps/proj3/i18n/en.json > has 100 keys and messages

 

/libs/cq/i18n/dict.en.json loads 300 keys and messages which is not at all required. Any way to fix this?