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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to get resource bundle (for localization) in custom workflow process step

Avatar

Avatar
Validate 1
Level 1
Sumit1191
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Sumit1191
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
Sumit1191
Level 1

18-12-2020

How to get i18Dictionary object in custom workflow process step?

Following points tried :
1. As we dont have slingHttpRequest object exists so can not get resource bundle using request.
2. ResourceBundle rb = ResourceBundle.getBundle("projectName");
3. ResourceBundle rb = ResourceBundle.getBundle("project full qualified name");

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

274 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

274 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

21-12-2020

@Sumit1191 

Try below snippet

    @Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)") 
	private ResourceBundleProvider resourceBundleProvider;
	
	@Override
	public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
		Locale locale = new Locale("de");
		ResourceBundle resourceBundle = resourceBundleProvider.getResourceBundle(locale);
		I18n i18n = new I18n(resourceBundle);
    }

 

Answers (3)

Answers (3)

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

174 likes

Total Posts

183 posts

Correct Reply

55 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

174 likes

Total Posts

183 posts

Correct Reply

55 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

18-12-2020

Hi @Sumit1191 

 

You can use ResourceBundleProvider to fetch the ResourceBundle when you do not have the request object.

 

Try this:

@Reference (target= "(component.name=org.apache.sling.i18n.impl.JcrBundleProvider)")
ResourceBundleProvider rbp;

 

ResourceBundle bundle = rbp.getResourceBundle(locale);

 

Reference: https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html

 

Thanks,

Kiran Vedantam.

 

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

174 likes

Total Posts

183 posts

Correct Reply

55 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

174 likes

Total Posts

183 posts

Correct Reply

55 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

18-12-2020

The I18n class has 2 constructors:

1. To present the string in the language that is specified in the user account

I18n i18n = new I18n(slingRequest);

2. For using the page locale:

Locale pageLang = currentPage.getLanguage(false);
ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLang);
I18n i18n = new I18n(resourceBundle);

 

Can you let me know how are you planning to trigger the workflow? Are you not using the servlet?

 

Thanks,

Kiran Vedantam.

Avatar

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
SureshDhulipudi
MVP

18-12-2020

Did you try getting Resource from workflow session?

 

// Get ResourceResolver from workflow session
final Map<String, Object> authInfo = new HashMap<>();
authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, workflowSession.getSession());
ResourceResolver resourceResolver = null;
Resource resource = null;
try{
resourceResolver = resourceResolverFactory.getResourceResolver(authInfo);
// Get the resource of payload
resource = resourceResolver.getResource(path);

}