To create i18n Object without slingRequest object | Community
Skip to main content
mkumar
May 17, 2016
Solved

To create i18n Object without slingRequest object

  • May 17, 2016
  • 3 replies
  • 3103 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kunal_Gaba_

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 

3 replies

Kunal_Gaba_
Kunal_Gaba_Accepted solution
May 18, 2016

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 

May 18, 2016

Hi,

One approach I can think of is as below :

import com.day.cq.i18n.I18n;

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

mkumar
mkumarAuthor
May 18, 2016

Thanks for the reply . I will try this approach.