Hello,
I have the following code in a JSP (as a part of a component):
<% Locale pageLocale = currentPage.getLanguage(true); if (pageLocale != null) { System.out.println("PageLocale is good :" + pageLocale.getCountry()); } ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLocale); if (resourceBundle != null ) { System.out.println("resourceBundle is good :" + resourceBundle.keySet().size()); } System.out.println("############################"); System.out.println(I18n.get(resourceBundle, "EmailAddress")); %>
In Author,
resourceBundle.keySet().size()
returns a number of the elements in the /apps/myapp/i18n tree - as expected.
When the page, containing the component, is moved to the Publisher this method returns zero elements.
Any ideas why that could be?
Environment: AEM6.1 upgrade from 5.6
Thanks!
Views
Replies
Total Likes
For security reasons apps is restricted in publishers and it uses user session. If you login as admin you might see it. You can try giving every one read permission for /apps/myapp/i18n & if works use this as temporary workaround to work for all user. To be honest there was no valid use case to allow override the locale from the page path for i18n. If you have such strong use case then please file support case with justification to support it.
Views
Replies
Total Likes
I do have the permissions you've mentioned. Also, the user that is logged in is member of other groups. Those groups have read access to /apps/.. too.
Any other Ideas?
Thanks!
Views
Replies
Total Likes
Thanks for the response
bump and more clarification:
I have another page that is not "login specific" and it works just fine. I was hoping it was permissions related, but it does not appear to be.
What else can stop a ResourceBundle from loading resources?
Thanks for your help!
Views
Replies
Total Likes
Hi,
Just use below code to find Locale..Let me know if it works. I will explain it later.
----Jitendra
Views
Replies
Total Likes
Hi Jitendra,
Thanks for the reply.
If you look at the first post - the code snippet. The line that you've suggested is the first line in that code. It returns non null object as expected.
Regards.
Views
Replies
Total Likes
Does i18 folder structure accessible to anonymous user?.
---Jitendra
Views
Replies
Total Likes
I18n path /apps/myapp/i18n/en
Effective ACL policies for anonimous
anonymous /apps Allow jcr:read
inherited from everyone
Regards,
-N
Views
Replies
Total Likes
Some more debug code added:
<% Locale pageLocale = currentPage.getLanguage(true); if (pageLocale != null) { System.out.println("PageLocale is good :" + pageLocale.getCountry()); } ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLocale); if (resourceBundle != null ) { System.out.println("resourceBundle is good :" + resourceBundle.keySet().size()); } System.out.println("############################"); System.out.println(I18n.get(resourceBundle, "EmailAddress")); javax.jcr.Session ses = resourceResolver.adaptTo(Session.class); String nodePath="/apps/myapp/i18n/en"; Resource resources = slingRequest.getResourceResolver().getResource(nodePath); Node en = resources.adaptTo(Node.class); System.out.println(en.getProperty("jcr:createdBy").getString()); System.out.println("User: "+ses.getUserID()); Node anyOfTheseWordsNode = en.getNode("anyOfTheseWords"); System.out.println(anyOfTheseWordsNode.getProperty("sling:message").getString()); %>
Here is the result in stdout.log :
PageLocale is good : resourceBundle is good :0 ############################ EmailAddress admin User: oreo.ebeling@gmail.com Any of these words
I think this rules out permission problems.
Any ideas are appreciated.
Regards,
-N
Views
Replies
Total Likes
bump.
Views
Replies
Total Likes
Do you have a fresh AEM 6.1 install to test on - i have seen funny issues with AEM that are update graded from previous versions. Test on Fresh install to rule out some sort of upgrade issue.
Views
Replies
Total Likes
Thanks for your reply, Scott.
I do have "clean", "test" AEM 6.1 environment, but in order to test I have to port the users/groups and ACLs from the pgraded environment.
Users/groups are easy to deal with - package them and deploy. But ACLs - I'm afraid I have no way of porting them, short of spending time to recreate all of the,
But then again. This leaves the issue with the upgraded environment (hosted by AMS). We must resolve this in the "in-place" upgrade environment.
The wired part is that the request object is loosing reference to the ResourceBundle. It is not empty (null) but the key set map is empty. There is a class instance that is called before the JSP is rendered (you can call it a front controller).I placed there some logging and the result is the same - empty key/value map in ResourceBundle. I've pegged a logger for SlingHttpServletRequest and it's package (org.apache.sling.api) in OSGI, but I did not get even a trace in the log file. Also - no permission related warnings/errors (as usually happens) in the error.log. From the code I've attached is clean that the session has access to the nodes under apps/myapp/i18n and a level deeper.
It appears that I'll have to open a ticket with DayCare and have one of their engineers take a look.
Regards,
-N
Views
Replies
Total Likes
Can you test again by calling the <cq:setContentBundle> tag before getting the locale from the request ?
https://docs.adobe.com/docs/en/cq/5-6/howto/taglib.html#%3Ccq:setContentBundle%3E
Views
Replies
Total Likes
Thanks for the suggestion, Kunal!
yep.. tried that.
In general I keep this tag in my global.jsp that overloads /libs/foundation/global.jsp and every(almose) jsp includes it.
Also added it explicitly before the code snippet provided - directly on the component jsp.
No dice...:(
Regards,
-N
Views
Replies
Total Likes
Ok. May be you can debug whether the i18n is being called when your request the page on publish box - Make a request to your page on publisher box and go to http://localhost:4503/system/console/requests. In the recent requests list find out the last request to the page with .html extension. In the request log search for the following - org.apache.sling.i18n.impl.I18NFilter. This filter should be called as it is responsible for binding the resourcebundle with the request object. You can see the source here - https://github.com/apache/sling/blob/4e24494b17579b15cf8ce31af5152854ee913d6f/bundles/extensions/i18...
Views
Replies
Total Likes
Hmm ..that is an interesting idea.
Looked at the request. I18NFilter filter is called 2 times:
62 LOG Filter timing: filter=com.adobe.granite.csrf.impl.CSRFFilter, inner=58, total=58, outer=0 62 LOG Filter timing: filter=org.apache.sling.security.impl.ContentDispositionFilter, inner=58, total=58, outer=0 62 LOG Filter timing: filter=org.apache.sling.i18n.impl.I18NFilter, inner=58, total=58, outer=0
As of the the Impl class - it is not on the Uber jar file and I have only the obfuscated version, Also I think Adobe might provide their own implementation. I'll dig more around.
Will try also to put a logger for the
org.apache.sling.i18n
package.
Regards,
-N
Views
Replies
Total Likes
So, a few things are important and you need to understand how Locale works in AEM. You page must have jcr:language property. Does your page has this property?. If property isn't found in currentPage, API tries to resolve it in other paths.
here are the details about Page API for the Locale.
Locale getLanguage(boolean ignoreContent) -----Returns the content language of the page. The language is usually defined on the page content via ajcr:language
property containing the iso codes for language and country. if the property is not defined on this page all ancestors are search for such an property. If no language is defined at all, the path is examined if it contains a iso label. If no language can be found at all, the systems default locale is returned. IfignoreConent
istrue
, only the names of the path is used to determine the language. Note that this has nothing to do with i18n of the cq5 itself.
ignoreContent
- if true
only the path is used to determine the language.
Views
Replies
Total Likes
Views
Like
Replies