Thanks Matteo, Grégory and Richard for your very detailed help! In fact it took
all three of you to solve the problem:
- Matteo to confirm me in what I thought I've read before (that the behavior
should be transparent)
- Richard to lead me on the right track for setting up i18n correctly
- and Grégory for the "mgnl.i18n" trick
So again: Thanks very much!
If I may post a follow-up question: Grégory said "...if somehow the node you're
looking at wasn't wrapped...". In my case the model class does a query and
returns a collection of Content objects. I guess these objects should be
wrapped before being returned. Can anyone post a few lines of code showing how
this is done correctly? All the sample model classes I've examined don't return
wrapped content objects but custom beans (e.g. NavigationItem etc.)...
Thanks!
-will
On 01.03.2011, at 17:23, Unger, Richard wrote:
>
> Hi Will!
>
> If you set up the i18n correctly for a site, the output of content in the
> correct language should be transparent to you.
>
> So, assuming you enable english and german, and set german as the default
> language, then if the site is accessed via:
>
> www.mysite.com/siteroot/contentpage --> contentpage will show up in German
> www.mysite.com/en/siteroot/contentpage --> contentpage will show up in
> English
>
> In the same way, ${content.field} will return the correct value, based on the
> currently selected language.
>
> You can find the currently selected language via
> getAggregationState().getLocale()
> You can find the user's preferred language via getUser().getLocale()
> You can find the browser's language via getContext().getLocale()
>
> Normally, you should not have to mess with those variables though. The only
> reason I found for reading those variables was in order to create a
> navigation for switching language on the public site. On the author site you
> can switch language using the controls in the pagebar.
> On the public site you may want to provide flag-buttons, they can link to the
> current page in a different language by setting the link to something like:
> ${contextPath + "/en" + content.@handle}
> In order to highlight the currently selected language, you can test [# if
> state.locale.language=="en"] ... [/#if]
> --> remember, the aggregationState contains the selected language!
>
> Regards from Vienna,
>
> Richie
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> [mailto:[email protected]] Im Auftrag von Will Scheidegger
> Gesendet: Dienstag, 01. März 2011 15:46
> An: Magnolia User-List
> Betreff: [magnolia-user] Freemarker i18n: Selecting the right node data to
> output
>
>
> Dear Magnolians
>
> Already my next stk / freemarker question that I could not answer with the
> help of the documentation...
>
> Let's say you have a localized title stored in the node datas "title_en" and
> "title_fr". What's the correct way to output the right version now? If you
> have the current language somewhere (be that in the site or whatever, for now
> just say in a variable "language") the best I could come up with is
>
> ${content['title_' + language]}
>
> but I was kind of expecting to find a special Magnolia trick for this... or
> am I missing something again?
>
> Thanks
> -will
>
>
>
>
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
>
>
>
>
>
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
>
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------