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
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
try with ResourceBundle e.g.
Locale pageLang = currentPage.getLanguage(
false
);
ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLang);
I18n i18n =
new
I18n(resourceBundle);
Views
Replies
Total Likes
could be problem with request object.
I18n i18n = new I18n(slingRequest);
|
more info - Internationalizing UI Strings
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Hi,
try with ResourceBundle e.g.
Locale pageLang = currentPage.getLanguage(
false
);
ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLang);
I18n i18n =
new
I18n(resourceBundle);
Views
Replies
Total Likes
Yes. That worked. Thanks for the help
Views
Replies
Total Likes
Views
Likes
Replies