Accessing I18n strings on backend

Avatar

Avatar

alvarof55440963

Avatar

alvarof55440963

alvarof55440963

22-11-2018

Hello folks. Hope you are doing great.

I'm having a weird problem with I18n object I created to get the translated strings before rendering my htl template. For example, I'm doing something like this:

var i18n = new Packages.com.day.cq.i18n.I18n(request);

var translated = i18n.get('Some string in my dictionary')

I have configured the language dictionaries properly and created a Spanish copy of the page I'm working on, but I always get the English text on the `translated` variable

I know that the translations are working because if in the HTL I write something like this

${'Some string in my dictionary' @ i18n}

then I can see the Spanish version of the text in the html, so the dictionary is well configured.

Do I need to do anything else to get the translated string in the backend??

Thanks

View Entire Topic

Avatar

Avatar

alvarof55440963

Avatar

alvarof55440963

alvarof55440963

23-11-2018

Hi, thanks for answering. The problem is that according to this: HTL Global Objects  "request" is an instance of org.apache.sling.api.SlingHttpServletRequest So I think it is the correct object