Re: can't get setting locale to work
"Jonathan Revusky" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
You're right, as usual. For some reason, I thought her message said something about internationalizing parts of the page, but I just reread it and she doesn't say that. Or maybe I thought that because the discussion was about setting the .locale from within a template. Of course, it's pretty rare to want part of the page to be in English and the rest in Spanish, I suppose. Typically, the locale-setting should be set in application logic outside the template and then if there is a localized version of a template using the standard naming scheme, it is just used transparently. At least that was the idea... JR On Sat, Aug 23, 2008 at 2:24 AM, Daniel Dekany <[email protected]> wrote: > Saturday, August 23, 2008, 4:17:56 AM, Jonathan Revusky wrote: > >> On Fri, Aug 22, 2008 at 1:17 PM, Anna Putnam <[email protected]> wrote: >>> Great! Thanks that makes sense (and works). I guess I should have stated my true objective. I am in the process of internationalizing my app. In >>> some cases I would like the browser language to drive which locale to use but in others I would like to override this behavior and force either English >>> or Spanish depending on the case. Is there an easy way to do this? I thought the setting approach below would do it but it is not working for me. Any >>> suggestions? >> >> You are on the right track, I think. If there are template sections >> that are internationalized according to some logic, perhaps the best >> thing is to use #include after setting the .locale as already >> described. > > That's hardly a good advice, as for using #include: > > (a) You already have to be in a template, that maybe itself has > localized variations > > (b) You already have to have the locale set correctly (like based on > the detected browser locale) > >> Then you basically leverage the fact that template loading >> has locale logic built-in. Your code can have >> >> [#include "foo.ftl"] >> >> and, if the .locale is es_ES, it will, with no special configuration >> on your part, look for foo_es_ES.ftl and then foo_es.ftl and fall back >> on foo.ftl. >> >> JR >> >>> >>> Thanks again, >>> Anna >>> >>> -----Original Message----- >>> From: Daniel Dekany [mailto:[email protected]] >>> Sent: Friday, August 22, 2008 1:14 PM >>> To: Anna Putnam >>> Cc: [email protected] >>> Subject: Re: [FreeMarker-user] can't get setting locale to work >>> >>> Friday, August 22, 2008, 9:57:55 PM, Anna Putnam wrote: >>> >>>> I am having trouble using >>>> <#setting locale="es_ES"/> >>>> >>>> I have this in my ftl code: >>>> >>>> <h1>${locale}</h1> >>>> <#setting locale="es_ES"/> >>>> <h1>${locale}</h1> >>>> >>>> And always my page has: >>>> >>>> <h1>en_US</h1> >>>> <h1>en_US</h1> >>>> >>>> Is there other configuration that I need to make this work? >>> >>> When you write ${locale}, you print the *plain* variable (most >>> certainly a data-model variable) called "locale". That you could set >>> as <#assign locale = "es_ES">, but as it is just a plain variable it >>> wouldn't have any special meaning for FreeMarker. Now, when you write >>> write <#setting locale="es_ES"> (as opposed to #assign) then you set the >>> FreeMasker *setting* called "locale". For reading the value of that >>> setting you can use the *special* variable called "locale", and for >>> referring to special variable you use an initial dot, like this: >>> ${.locale} >>> >>>> I am using freemarker version 2.3.8 >>>> >>>> Thank you in advance. >>>> >>>> -Anna >>>> >>>> >>> >>> -- >>> Best regards, >>> Daniel Dekany >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge >>> Build the coolest Linux based applications with Moblin SDK & win great prizes >>> Grand prize is a trip for two to an Open Source event anywhere in the world >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>> _______________________________________________ >>> FreeMarker-user mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/freemarker-user >>> >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge >> Build the coolest Linux based applications with Moblin SDK & win great prizes >> Grand prize is a trip for two to an Open Source event anywhere in the world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> FreeMarker-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/freemarker-user > > -- > Best regards, > Daniel Dekany > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/