Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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
Level 10

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
Level 10

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.