4 Replies Latest reply on Jul 9, 2013 9:51 AM by jerfree

    sling:message customization per project using i18n

    jerfree

      Hi all,

       

       

      I saw this post on the sling message boards, which is the same question as mine, but I didn't see a resolution:

      http://apache-sling.73963.n3.nabble.com/Overriding-of-sling-messages-in-sling-i18n-td40206 15.html

       

      In our scenario, this is more about site localization than internationization, in that we may re-use components in multiple sites, but want to be able to customize header text using i18n.

       

      For example, the default component, and the jsp for it, may live in:

       

      /apps/defaultsite/components/mycomponent

       

      under that component I have:

       

      /en/

           key1 (sling:key="Lorem", sling:message="ipsum")

       

      For a specific site that will be using that component, I want to override key 1 to use something different for the message, I create a new component at:

       

      /apps/customsite/components/mycomponent  and have it's sling:resourceSuperType reference the component listed above (/apps/defaultsite/components/mycomponent)

       

      I then create my sling message under my new component:

       

      /en/

           key1 (sling:key="Lorem", sling:message="customsite")

       

      The behavior I see (which the other post also mentions) is that whatever translation was saved last is what gets rendered onto the page, the logic for i18n doesn't look like it can be set at multiple places and then have the sling:resourceType and resourceSuperType resolution be used to figure out which value to use.

       

       

      Is there another approach to use so I can override sling messages at the component level when a component inherits from another component that already was using the same sling:message?

       

      Thanks!

        • 1. Re: sling:message customization per project using i18n
          aklimets Adobe Employee

          The sling:message dictionaries are merged globally, respecting the search path (so a string in /apps overrides one in /libs, but multiple strings with the same key in /apps have an undefined winner). It does not know anything about components or resource types.

           

          But there is the <cq:setContentBundle> JSP tag which will look for those strings as properties in the local component instance node first before it asks the resource bundle from the sling request object aka the i18n dictionaries.

          • 2. Re: sling:message customization per project using i18n
            jerfree Level 1

            Thanks for the suggestion, that sounds exactly what I need to use, but I am not seeing the expected result.

             

            Do you see anything wrong with the node structure listed below?

             

            baseproject

             

            components

                 mycomponent

                      mycomponent.jsp - uses <cq:setContentBundle /> in code along with <fmt:message key="mykey"/> to get value

                      i18n (sling:folder)

                           en (sling:folder)

                                *jcr:language=en

                                *jcr:mixinTypes="mix:language"

                                mykey (sling:MessageEntry)

                                     *sling:key="mykey"

                                     *sling:message="base message"

             

             

            Extendedproject

             

            components

                 mycomponent

                      *sling:resourceSuperType=baseproject/components/mycomponent

                      i18n (sling:folder)

                           en (sling:folder)

                                *jcr:language=en

                                *jcr:mixinTypes="mix:language"

                                mykey (sling:MessageEntry)

                                     *sling:key="mykey"

                                     *sling:message="extended message"

             

             

            I place "mycomponent" from the "extendedproject" onto a page.  That component has a supertype referencing the component in the baseproject, where the jsp logic lives.

             

            I expect to see the "extended message" appear, since cq:setContentBundle should tell the page to use the i18n message assigned to this component itself from "extendedproject".

             

            However, what I see is whichever sling message was saved last is the one that displayed.  I think what you listed above for " (so a string in /apps overrides one in /libs, but multiple strings with the same key in /apps have an undefined winner)" is still being applied, and the cq:setContentBundle doesn't seem to find the message tied to the component itself in the context of the app it lives within.

             

            Thanks!

            • 3. Re: sling:message customization per project using i18n
              aklimets Adobe Employee

              This i18n folder you have in the component location (say /apps/foo/components/mycomponent) is wrong. It would be picked up as normal dictionary.

               

              What I meant with the cq:setContentBundle tag was those properties in each component instance. For example, /content/mysite/de/page/jcr:content/par/comp. The structure would not be a dictionary, so no jcr:language, no sling:Message etc. but plain properties that have the same name as the keys = original strings.

               

              /content/mysite/de/page/jcr:content/par

                  + comp

                      - Word = "Wort"

                     - House = "Haus"

                     - Tree = "Baum"

               

              This way you can easily make this settable in the edit dialog of the component, using "Word", "House" etc. as field names. There is a little restriction for the keys since they must be valid JCR property names (e.g. no colons), but that should be rare.

               

              You might have picked up the /libs/foundation/components/search/i18n example - this is only there for backwards compatibility for that specific component.

              • 4. Re: sling:message customization per project using i18n
                jerfree Level 1

                Thanks again!

                 

                It works correctly once I define those properties on the instance of the component itself.  However, I that approach won't will work for us, the values we want to set for the components shouldn't be edited in a dialog, and we don't want them to be configured per an instance, but instead per the component in a given app folder.

                 

                We will have components that are used by several sites (the sites are all in english).  We want to be able to define a component in a location like /apps/baseapp/components/mycomponent, and be able to define the default text header for that component.  Let's say that heading is "Recent Stories".

                 

                In site A, we have a component located at /apps/sitea/components/mycomponent, and it's supertype is /apps/baseapp/components/mycomponent, and we rely on the supertype jsp to render the component.

                 

                We want to be able to have the heading of the component, when referenced anywhere in site A, be overridden to say "Recent Blogs" instead.  If we didn't override the heading, it would default to the supertype's heading of "Recent Stories".

                 

                So the only thing we want to change about our component in siteA is the heading, everything else rendered is just inherited from it's supertype.

                 

                I take it what I describe above we won't get OOTB with Sling and AEM, is that correct?

                 

                We can look at implementing our own custom solution to solve this if we need to.

                 

                Thanks!