Re: can't get setting locale to work

Anna Putnam <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
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?

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=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.