You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Dirk Rudolph <Di...@t-systems-mms.com> on 2012/11/06 17:54:28 UTC
Overriding of sling:messages in sling i18n
Hi all,
in one of our CQ5 projects we want to use a kind of inheritance of system
texts configured using the sling i18n support.
We have the following content structure for our system texts:
/apps/foo/i18n/en
- key1 (sling:key=Lorem, sling:message=ipsum)
- key2 (sling:key=Dolor, sling:message=sit)
/apps/bar/i18n/en
- key2 (sling:key=Dolor, sling:message=amet)
I assume that when I use <fmt:message key=Dolor/> the translation located
below /apps/bar is used.
I had a look at the source of JcrContentBundle to understand how
JcrContentBundleProvider/JcrContentBundle works. There I found the query
which is used to search for all sling:MessageEntries (Example):
//element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,slin
g:Message)[@sling:message]/(@sling:key|@sling:message)
With the result in our case:
/apps/bar/i18n/en/key1
/apps/foo/i18n/en/key1
/apps/foo/i18n/en/key2
And the resulting ResourceBundle:
{Lorem=ipsum, Dolor=sit}
Afterwards I had a look at the algorithm that is used to override the keys
if they exists twice and mentioned that it depends on the ordering of the
searchpaths so I configured my searchpaths as follows:
[/apps/,/apps/bar, /apps/foo/]
This means that in line 150 the keys found below /apps/foo are overridden by
/apps/bar and /apps. Now the problem is that every key below /apps/bar and
/apps/foo is also below /apps so the keys are all sorted into the same Map
because of the none-reversed iteration order in line 139. Wouldnt it be
better when the iteration order in 150 and 139 is the? If not is there any
other way to do basic overriding of i18n messages?
Thanks a lot,
Dirk Rudolph
T-Systems Multimedia Solutions GmbH
Organisationseinheit CCS
Dirk Rudolph
Software-Entwicklung
Hausanschrift: Riesaer Straße 5, 01129 Dresden
Postanschrift: Postfach 10 02 24, 01072 Dresden
+49 351 2820-5363 (Tel)
E-Mail: <ma...@t-systems-mms.com>
Dirk.Rudolph@t-systems-mms.com
Internet: <http://www.t-systems-mms.de/> http://www.t-systems-mms.com
T-Systems Multimedia Solutions GmbH
Aufsichtsrat: Ulrich Meister (Vorsitzender)
Geschäftsführung: Peter Klingenburg, Dr. Jens Nebendahl
Handelsregister: Amtsgericht Dresden HRB 11433
Sitz der Gesellschaft: Dresden
Ust-IdNr.: DE 811 807 949
Re: Overriding of sling:messages in sling i18n
Posted by Alexander Klimetschek <ak...@adobe.com>.
(that's a bit OT for this list, maybe better discussed on the CQ forums [0])
On 07.11.2012, at 17:06, Dirk Rudolph <Di...@t-systems-mms.com> wrote:
> I18n.get(resourceBundle, "Press here");
> ...
> And the Translations are:
>
> /apps/lib/i18n/en
> - key1 (sling:key = "Press here", sling:message = "Press here")
> /apps/anApp/i18n/en
> - key1 (sling:key = "Press here ((anApp))", sling:message = "Press
> the button")
>
> With this content I have to use "anApp" as comment in the I18n.get()
> invocation.
Right.
> But when I want to use the component located in the lib I'm not
> able to set this parameter (I don't want to copy the components jsp into my
> app)
Ok, but I guess you maybe use the dictionary for something else here?
Why would normal translations be different if it's the exact same unchanged code and original strings? If the meaning changes, usually the original string changes (or at least one of them) and you need to adapt the code anyway.
At least I haven't seen this case at all.
[0] http://forums.adobe.com/community/digital_marketing_suite/cq5
Cheers,
Alex
AW: Overriding of sling:messages in sling i18n
Posted by Dirk Rudolph <Di...@t-systems-mms.com>.
When I understood the API of com.day.cq.i18n.I18n right if have to use one
of the get methods to translate my system texts. For example in the
previously mentioned library:
/apps/lib/components/aComponent/aComponent.jsp
<%
I18n.get(resourceBundle, "Press here");
%>
Now I want to include this component in my app:
/apps/anApp/components/page/page.jsp
<sling:include resource="${resource}"
resourceType="lib/components/aComponent" />
And the Translations are:
/apps/lib/i18n/en
- key1 (sling:key = "Press here", sling:message = "Press here")
/apps/anApp/i18n/en
- key1 (sling:key = "Press here ((anApp))", sling:message = "Press
the button")
With this content I have to use "anApp" as comment in the I18n.get()
invocation. But when I want to use the component located in the lib I'm not
able to set this parameter (I don't want to copy the components jsp into my
app)
Am I right? Can you give an example that shows how to use the I18n API for
this use case?
Cheers,
Dirk
-----Ursprüngliche Nachricht-----
Von: Alexander Klimetschek [mailto:aklimets@adobe.com]
Gesendet: Mittwoch, 7. November 2012 12:07
An: users@sling.apache.org; Dirk.Rudolph@t-systems-mms.com
Betreff: Re: Overriding of sling:messages in sling i18n
On 07.11.2012, at 10:06, Dirk Rudolph <Di...@t-systems-mms.com>
wrote:
> When I now introduce an "app" that should use the component defined in
> the lib, they shouldn't use the keys defined in the lib because it's
> possible that a translation of one message differs for different "apps"
This is IMHO a typical scenario for using translation comments as mentioned.
Cheers,
Alex
Re: Overriding of sling:messages in sling i18n
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 07.11.2012, at 10:06, Dirk Rudolph <Di...@t-systems-mms.com> wrote:
> When I now introduce an "app" that should use the component defined in the
> lib, they shouldn't use the keys defined in the lib because it's possible
> that a translation of one message differs for different "apps"
This is IMHO a typical scenario for using translation comments as mentioned.
Cheers,
Alex
AW: Overriding of sling:messages in sling i18n
Posted by Dirk Rudolph <Di...@t-systems-mms.com>.
Hi Alex, thanks for your reply.
We have a "library" that defines some components used for different "apps".
/apps/lib/components/aComponent
This component uses the keys defined below /apps/lib/i18n.
When I now introduce an "app" that should use the component defined in the
lib, they shouldn't use the keys defined in the lib because it's possible
that a translation of one message differs for different "apps" (That's also
why the use of a basename for each app wasn't successful in our case). Due
to this I want to override a baseset of translations located in the lib by a
subset of translations located below the "app" (/apps/anApp/i18n). I looks
like the only way to do this is to provide a special order of search paths
because this is the only way the overriding can be influenced without
touching the code.
Thanks a lot,
Dirk
Re: Overriding of sling:messages in sling i18n
Posted by Alexander Klimetschek <ak...@adobe.com>.
The mechanism was mainly designed for a basic search path using /apps and /libs. What is your use case with a search path like /apps/,/apps/bar, /apps/foo/ and localization?
If you just want to separate dictionaries:
a) use different translation hints/comments for identical strings that need different translations in a different context; in CQ's i18n apis the key (for the resource bundle / sling:key) is built using "<string> ((<comment>))" if a comment is present
b) you can have different dictionaries with a different "basename" [0] and access using [1]
[0] http://sling.apache.org/site/internationalization-support.html
[1] http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/SlingHttpServletRequest.html#getResourceBundle(java.lang.String,%20java.util.Locale)
HTH,
Alex