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-US.json (We need only this one)
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.
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:
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
With above 2 pointers, you will be able to make a call to the servlet/set locale per your need.(for content specific call)