Load Site Specific Dictionary | Community
Skip to main content
Level 5
October 5, 2020
Solved

Load Site Specific Dictionary

  • October 5, 2020
  • 1 reply
  • 1400 views

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,

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vijayalakshmi_S

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)

1 reply

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
October 6, 2020

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)

prashantonkar
Level 4
October 13, 2021

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?