It would be great to have a feature to easily inject a i18n Helper to resolve translations from the i18n files.
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:
furthermore it would be nice to have an option to mock the i18n object, when using the AemContext.
which was not a problem in the injector but in or page mock - fixed in master
Can you please retest and close this ticket afterwards? I18n in Components works fine for me now, thank
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.
please do not reopen already implemented feature tickets for bug reports - i've created