[JIRA] (WCMIO-21) Add support for i18n to AdapterFactory

97 views
Skip to first unread message

Alexander Muthmann (JIRA)

unread,
Oct 15, 2014, 9:58:00 AM10/15/14
to wcm-i...@googlegroups.com
Alexander Muthmann created WCMIO-21:
---------------------------------------

Summary: Add support for i18n to AdapterFactory
Key: WCMIO-21
URL: https://wcm-io.atlassian.net/browse/WCMIO-21
Project: wcm.io
Issue Type: New Feature
Components: WCM
Reporter: Alexander Muthmann


It would be great to have a feature to easily inject a i18n Helper to resolve translations from the i18n files.



--
This message was sent by Atlassian JIRA
(v6.4-OD-07-004#64005)

Stefan Seifert (JIRA)

unread,
Oct 15, 2014, 10:46:00 AM10/15/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert resolved WCMIO-21.
---------------------------------
Assignee: Alexander Muthmann
Fix Version/s: AEM Sling Models Extensions 1.1.0
Resolution: Fixed

master 261a9ed

snapshot version 1.0.1-SNAPSHOT

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Alexander Muthmann
> Fix For: AEM Sling Models Extensions 1.1.0

Alexander Muthmann (JIRA)

unread,
Oct 16, 2014, 10:38:00 AM10/16/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10131#comment-10131 ]

Alexander Muthmann commented on WCMIO-21:
-----------------------------------------

Currently it does not seem to be possible to use the i18n class with a request as source.
SlingHttpServletRequestImpl always returns a NullResourceBundle, no matter which languages/translations are available.

A solution is to use the ResourceBundleProvider-Service and get a ResourceBundle from it.

By default an implementation "PseudoTranslation" has the service-ranking 1000, the Sling implementation "org.apache.sling.i18n.impl.JcrResourceBundleProvider" has no service-ranking defined. Therefor it is required to either iterate over all Services or load the Sling implementation. If I understand the documentation correctly, the interface should not be implemented by another service:
{quote}This service interface is not intended to be implemented outside of the sling.i18n bundle{quote}

To get an instance of i18n for the language of the currentPage, this code works fine:
{code}
SlingBindings bindings = (SlingBindings)request.getAttribute(SlingBindings.class.getName());
SlingScriptHelper scriptHelper = bindings.getSling();
ResourceBundleProvider bundleProvider = scriptHelper.getServices(ResourceBundleProvider.class, "(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)")[0];
ResourceBundle resourceBundle = bundleProvider.getResourceBundle(currentPage.getLanguage(true));
I18n i18n = new I18n(resourceBundle);
{code}

Alexander Muthmann (JIRA)

unread,
Oct 16, 2014, 10:38:00 AM10/16/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Muthmann reopened WCMIO-21:
-------------------------------------
Assignee: Stefan Seifert (was: Alexander Muthmann)

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Stefan Seifert

Stefan Seifert (JIRA)

unread,
Oct 17, 2014, 6:38:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10133#comment-10133 ]

Stefan Seifert commented on WCMIO-21:
-------------------------------------

we you've passed "true" to the getLanguage class? this ignored a language that may be set in the page properties of a hierarchy page. i think we should respect this if set by the editor.

Stefan Seifert (JIRA)

unread,
Oct 17, 2014, 6:38:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10133#comment-10133 ]

Stefan Seifert edited comment on WCMIO-21 at 10/17/14 12:37 PM:
----------------------------------------------------------------

why you've passed "true" to the getLanguage class? this ignored a language that may be set in the page properties of a hierarchy page. i think we should respect this if set by the editor.


was (Author: sseifert):

Alexander Muthmann (JIRA)

unread,
Oct 17, 2014, 6:43:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10134#comment-10134 ]

Alexander Muthmann commented on WCMIO-21:
-----------------------------------------

We don't have this setting in our project, so there was no reason to change the default autosuggestion of my alien ide ;)
But yes, false would make sense in a more general context.

Stefan Seifert (JIRA)

unread,
Oct 17, 2014, 7:08:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert resolved WCMIO-21.
---------------------------------
Assignee: Alexander Muthmann (was: Stefan Seifert)
Resolution: Fixed

master 099f11d

please give it a try with the latest snapshot

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Alexander Muthmann

Alexander Muthmann (JIRA)

unread,
Oct 17, 2014, 7:23:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Muthmann reopened WCMIO-21:
-------------------------------------
Assignee: Stefan Seifert (was: Alexander Muthmann)

No, the used ResourceResolver is the Pseudo-One which does not provide the actual translations :(
{code}
resourceBundleProvider = com.adobe.granite.i18n.impl.bundle.PseudoTranslations
{code}




> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Stefan Seifert

Stefan Seifert (JIRA)

unread,
Oct 17, 2014, 8:00:00 AM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert resolved WCMIO-21.
---------------------------------
Assignee: Alexander Muthmann (was: Stefan Seifert)
Resolution: Fixed

master 5c3b393

works?

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Alexander Muthmann

Stefan Seifert (JIRA)

unread,
Oct 17, 2014, 12:13:00 PM10/17/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10139#comment-10139 ]

Stefan Seifert commented on WCMIO-21:
-------------------------------------

master c74e399

it is finally working now. the original request seemed to used a different filter wrapping set than that from the slingbindings, with the latter it works.

Igor Sechyn (JIRA)

unread,
Oct 20, 2014, 4:05:45 AM10/20/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10201#comment-10201 ]

Igor Sechyn commented on WCMIO-21:
----------------------------------

i can confirm, that this is working, but the injection of the i18n object makes it impossible to write unit tests for request based models. it always throws following exception:
{code}
[main] ERROR org.apache.sling.models.impl.ModelAdapterFactory - unable to create object
java.lang.UnsupportedOperationException
at io.wcm.testing.mock.aem.MockPage.getLanguage(MockPage.java:296)
{code}

furthermore it would be nice to have an option to mock the i18n object, when using the {{AemContext}}.

Alexander Muthmann (JIRA)

unread,
Oct 20, 2014, 4:06:44 AM10/20/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Muthmann reassigned WCMIO-21:
---------------------------------------

Assignee: Stefan Seifert (was: Alexander Muthmann)

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Stefan Seifert

Stefan Seifert (JIRA)

unread,
Oct 20, 2014, 5:08:44 AM10/20/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert reassigned WCMIO-21:
-----------------------------------

Assignee: Alexander Muthmann (was: Stefan Seifert)

which was not a problem in the injector but in or page mock - fixed in master

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Alexander Muthmann

Alexander Muthmann (JIRA)

unread,
Oct 20, 2014, 5:09:44 AM10/20/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Muthmann reassigned WCMIO-21:
---------------------------------------

Assignee: Igor Sechyn (was: Alexander Muthmann)

Can you please retest and close this ticket afterwards? I18n in Components works fine for me now, thank [~sseifert]

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Igor Sechyn

Stefan Seifert (JIRA)

unread,
Dec 3, 2014, 3:42:02 PM12/3/14
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert closed WCMIO-21.
-------------------------------
Assignee: (was: Igor Sechyn)

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Fix For: AEM Sling Models Extensions 1.1.0
>
>
> It would be great to have a feature to easily inject a i18n Helper to resolve translations from the i18n files.



--
This message was sent by Atlassian JIRA
(v6.4-OD-11-012#64007)

Igor Sechyn (JIRA)

unread,
Jan 9, 2015, 10:28:01 AM1/9/15
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Sechyn reopened WCMIO-21:
------------------------------
Assignee: Stefan Seifert

There is another issue with the injection of the I18n object, when it is injected in models adapted for example from the Request of the Post Servlet. In this case the SlingBindings attribute is not set, since no script resolving is involved. In this case the original request is used, which is the instance of the org.apache.sling.engine.impl.SlingHttpServletRequestImpl3 class. This instance returns the NullResourceBundle, which does not provide any i18n support.

the only workaround I came up with, was to use the resource for adaption instead of request, in this case the AemInjector uses the request from ModelsImplConfiguration service and everything works fine.

As a solution when injecting the I18n object, we might want to try the slingBindings request, then fallback to the one from ModelsImplConfiguration and only then try the original one.

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Stefan Seifert
> Fix For: AEM Sling Models Extensions 1.1.0
>
>
> It would be great to have a feature to easily inject a i18n Helper to resolve translations from the i18n files.



--
This message was sent by Atlassian JIRA
(v6.4-OD-12-026#64007)

Stefan Seifert (JIRA)

unread,
Jan 14, 2015, 6:07:01 AM1/14/15
to wcm-i...@googlegroups.com
Resolution: Fixed

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Fix For: AEM Sling Models Extensions 1.1.0
>
>
> It would be great to have a feature to easily inject a i18n Helper to resolve translations from the i18n files.



--
This message was sent by Atlassian JIRA
(v6.4-OD-13-024#64009)

Stefan Seifert (JIRA)

unread,
Jan 14, 2015, 6:07:01 AM1/14/15
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert reopened WCMIO-21:
---------------------------------
Assignee: (was: Stefan Seifert)

Stefan Seifert (JIRA)

unread,
Jan 14, 2015, 6:07:01 AM1/14/15
to wcm-i...@googlegroups.com

[ https://wcm-io.atlassian.net/browse/WCMIO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert closed WCMIO-21.
-------------------------------
Resolution: Fixed

please do not reopen already implemented feature tickets for bug reports - i've created WCMIO-50

> Add support for i18n to AdapterFactory
> --------------------------------------
>
> Key: WCMIO-21
> URL: https://wcm-io.atlassian.net/browse/WCMIO-21
> Project: wcm.io
> Issue Type: New Feature
> Components: WCM
> Reporter: Alexander Muthmann
> Assignee: Stefan Seifert
Reply all
Reply to author
Forward
0 new messages