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");
Solved! Go to Solution.
Views
Replies
Total Likes
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);
}
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);
}
Actually the payload is Content Fragment.
Also using the path I got resource as well.
But how we can get Resource Bundle (Dictionary object) using it.
Views
Replies
Total Likes
@reference(target = "(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)")
private ResourceBundleProvider resourceBundleProvider;
ResourceBundle resourceBundle = getResourceBundleProvider().getResourceBundle(locale);
I18n i18n = new I18n(resourceBundle);
Views
Replies
Total Likes
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.
We are planning to trigger workflow manually.
As you mentioned 2 ways to get i18n object, we need slingRequest object, but we don't have the object in process step.
Views
Replies
Total Likes
Views
Replies
Total Likes
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.
I tried above solution, its not working. State of the process step is showing Unsatisfied.
Views
Replies
Total Likes
Views
Replies
Total Likes
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);
}
Views
Replies
Total Likes
Views
Likes
Replies