Can I get entire i18n labels of specific dictionary

Viewed 4119

I am facing an issue with i18n labels.

My application reads few i18n labels at js frontend using Granite.I18n.get('') function. The entire dictionary gets downloaded as ‘/libs/cq/i18n/dict.{+locale}.json’ as dictated in ‘/etc/clientlibs/foundation/shared/source/init.js’.

Now the en dictionary returns only the custom labels and is small size. But other languages like fr,the dictionary file is aggregation of all /libs dictionary and is very huge. I noticed this in few other sites also.

tennantco.com

en dictionary - 118 KB

fr dictionary - 1.4 MB

Timewarnercable.com

en dictionary - 1.1 KB

fr dictionary - 1.2 MB

Thermofisher

en dictionary - 3 KB

fr dictionary - 695 KB

Our pain point with this is, cost of caching this heavy file at CDN increases and trying to find a way to reduce CDN cost.

I understand en labels are the key itself. But the ExportServlet is able to filter out the render custom dictionary only for en. Our dictionaries are similar to otb dictionaries under /libs. Then how come ExportServlet treat otb labels under en export?

Is this bug common in all CMS products or specific to Adobe? Also need a solution or workaround to get custom dictionary only for other languages.

4 Answers

We faced the similar requirement to fetch I18n values at client side using Granite.i18n Library This is what I did.

  1. Created a custom servlet which returns JSON response similar to
    ResourceBundleExportServlet.
  2. Loaded the bundle using basename and locale parameter - ResourceBundle resourceBundle = req.getResourceBundle(basename,
    pageLocale);
  3. Added sling:basename="basename_constant"' in language specific i18n xml file which resides in /apps/project-name/i18n folder. In my case, I am setting the value of locale itself ex: "zh_cn".

4.In clientlibs javascript file setting Granite.I18n.setUrlPrefix("/bin/custom/i18n/dict."); to fetch from
custom servlet URL. This doesn't requires modification of OOTB I18n.js

here is an answer that could help you when you are trying to get a specific dictionary: https://stackoverflow.com/a/55656153/14465431

look at the part where is mention the sling:basename

this also works for one site

example:

[sling:Language] > mix:language
mixin
- sling:basename (string)
- sling:basename (string) multiple

http://localhost:4502/libs/cq/i18n/dict.es.[sling:basename-value].json

OTB solution :)

Related