Well after reading more and more about locale I realize that it's kind
of very problematic to set the locale and encoding the right way while
not breaking something else.

So I decided to use a dirty hack to get the expected result. I wrote a
very simple function inside my view that would turn a date object into
a string with the date just as I wanted, just in case someone might
find it useful:

{{def str_date(date):
w=dict([(0,'Lunes'),(1,'Martes'),(2,'Miércoles'),(3,'Jueves'),
(4,'Viernes'),(5,'Sábado'),(6,'Domingo')])
m=dict([(1,'Enero'),(2,'Febrero'),(3,'Marzo'),(4,'Abril'),(5,'Mayo'),
(6,'Junio'),
            (7,'Julio'),(8,'Agosto'),(9,'Septiembre'),(10,'Octubre'),
(11,'Noviembre'),(12,'Diciembre')])
return w[date.weekday()]+" "+str(date.day)+" de "+m[date.month]+" "+str
(date.year)}}

And I placed this code inside my layout.html file so it can be used
from any page (that extends the layout).

About the question you made, I read something about django that
mentions they have their own locale middleware, and it allows to set
locale on a per user basis
(django.middleware.locale.LocaleMiddleware).

Thankyou for all the help.

On 14 ago, 16:23, Yarko Tymciurak <[email protected]> wrote:
> According tohttp://docs.python.org/library/i18n.html
>
> it's even worse than that, saying some implementations core-dump on changing
> locale...
>
> How do other web frameworks deal with this?  As it is, it seems that it's up
> to the
> applicatiion.
>
> On Fri, Aug 14, 2009 at 2:26 PM, mdipierro <[email protected]> wrote:
>
> > This does not solve the problem the in Python local is set per process
> > and not per-thread. Am I wrong?
>
> > Massimo
>
> > On Aug 14, 1:51 pm, Yarko Tymciurak <[email protected]> wrote:
> > >http://www.w3.org/International/questions/qa-accept-lang-locales
>
> > > Discusses a starting point, while (application responsibility) warning to
> > be
> > > sure to let the user set their locale.
>
> > > I think, Francisco, this is your answer.  You can find what you need to
> > get
> > > started in:
>
> > > request.env.http_accept_language
>
> > > and, as per article above, you should provide the session a way to modify
> > > this if used as a default starting setting.
>
> > > Hope that is helpful.
>
> > > Regards,
> > > - Yarko
>
> > > On Fri, Aug 14, 2009 at 1:42 PM, mdipierro <[email protected]>
> > wrote:
>
> > > > If you find a way let me know.
>
> > > > On Aug 14, 1:37 pm, Yarko Tymciurak <[email protected]> wrote:
> > > > > it would seem there should be some way to set it based on client, per
> > > > > session...
>
> > > > > On Fri, Aug 14, 2009 at 1:32 PM, mdipierro <[email protected]>
> > > > wrote:
>
> > > > > > This is a problem.
>
> > > > > > You must set the locale:
> > > > > >http://docs.python.org/library/locale.html
>
> > > > > > the problem is that you cannot setting the locale is not thread
> > safe.
> > > > > > It does not break your app but once you set it it affects all the
> > > > > > apps.
>
> > > > > > Massimo
>
> > > > > > On Aug 14, 1:06 pm, Francisco <[email protected]>
> > wrote:
> > > > > > > Hello.
>
> > > > > > > Thanks for the advise. I have tried what you said and now my
> > > > > > > application is in Spanish, but weekdays and month names are still
> > > > > > > displayed in English. When I  use the following code from within
> > my
> > > > > > > view:
>
> > > > > > > {{=consulta.fecha_consulta.strftime("%A %d %B %Y")}}
>
> > > > > > > the date is displayed as "Wednesday 12 de August 2009"
>
> > > > > > > Any other suggestions?
>
> > > > > > > Thanks a lot.
>
> > > > > > > On 13 ago, 02:12, mdipierro <[email protected]> wrote:
>
> > > > > > > > You do not need to do that.
>
> > > > > > > > Just use the EDIT page, create a language file for mexican and
> > > > > > > > translate the format strings. This will be taken care of
> > > > automatically
> > > > > > > > everywhere.
>
> > > > > > > > On Aug 12, 3:06 pm, Francisco <[email protected]>
> > > > wrote:
>
> > > > > > > > > Hello everyone.
>
> > > > > > > > > I have just started learning web2py. It's really great!
> > > > > > > > > Now the question I have is about the locale.
> > > > > > > > > I'm from Mexico so my applications must be in Spanish. In
> > some
> > > > part
> > > > > > of
> > > > > > > > > the application I want to get a date doing something like
> > this
> > > > from
> > > > > > > > > within a view:
>
> > > > > > > > > {{=consulta.fecha_consulta.strftime("%A %d %B %Y")}}
>
> > > > > > > > > and it works, but the date is displayed in English. In what
> > way
> > > > can I
> > > > > > > > > set the locale for the date to be displayed in Spanish?
>
> > > > > > > > > Thanks for the help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to