Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

To create i18n Object without slingRequest object

Avatar

Level 3

Hello Community,

I want to create  i18n object to get i18n key value. In my java class i don't have access to request object.  How can i create i18n object to get i18n key inside my java class.

Please suggest

Regards,

Vinay

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You can get the resource bundle without the request object by calling the Sling ResourceBundleProvider API. 

//Get the reference of bundle provider to get the resource bundle. @Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)") private ResourceBundleProvider resourceBundleProvider;

See the API docs for more details - https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/sling/i18n/ResourceBundleProvider.html 

View solution in original post

3 Replies

Avatar

Correct answer by
Employee Advisor

You can get the resource bundle without the request object by calling the Sling ResourceBundleProvider API. 

//Get the reference of bundle provider to get the resource bundle. @Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)") private ResourceBundleProvider resourceBundleProvider;

See the API docs for more details - https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/sling/i18n/ResourceBundleProvider.html 

Avatar

Level 9

Hi,

One approach I can think of is as below :

import com.day.cq.i18n.I18n;

I18n.get(getRequest(), "i18key")

Avatar

Level 3

Thanks for the reply . I will try this approach.