[Python-il] Newbie question: localizing dates without setlocale
Meir Kriheli
meir at mksoft.co.il
Tue Feb 19 15:17:43 IST 2008
Hi Udi,
Please reply to the list as well, so it'll be archived and accessible to
others.
Udi h Bauman wrote:
> Do you translate also the abbreviated month names, e.g., "Jan", "Feb"? I
> see it in the date filter, but it doesn't seem to work in Python code
> such as:
Yes I did:
http://code.djangoproject.com/browser/django/trunk/django/conf/locale/he/LC_MESSAGES/django.po#L3710
Which version of Django are you using ? Your version might not be the
most updated (can't remember when that short names translation went in -
don't think it's in 0.96), the revision of the commit is 6665.
> from time import strftime
> from django.utils.translation import gettext as _
>
> _( strftime( "%b", ( 0, 2, 0, 0, 0, 0, 0, 0, 0 ) ) ) # should return
> localized "Feb"
Why are you doing it in the view and not the template ? This is display
related - the code will be cleaner too. pass the date objects to the
template and use the date filter in it.
Cheers
--
Meir Kriheli
http://mksoft.co.il
> On Feb 19, 2008 2:30 PM, Udi h Bauman <dibaunaumh at gmail.com
> <mailto:dibaunaumh at gmail.com>> wrote:
>
> Great, I didn't know Django translates them. I just wrapped my call
> to strftime with a call to gettext.
>
> I'm aware of the search engine issue, & indeed needs to fix it. Is
> there a standard way to make the translation URL-based, or should I
> define URL's per language?
>
> Thanks a lot!
> Udi
>
>
> On Feb 19, 2008 12:45 PM, Meir Kriheli <meir at mksoft.co.il
> <mailto:meir at mksoft.co.il>> wrote:
>
> Udi h Bauman wrote:
> > Hi,
> >
> > I have a small question which I hope one of you experts will
> be kind
> > enough to help with.
> >
> > I wrote a web page which I need to translate to different
> languages
> > (http://staging.daylight-savings-time.info). I need to
> translate the day
> > & month names, which I generate using /strftime/. I need it to
> output
> > the date parts for a given locale. I've tried using setlocale,
> but it
> > apparently affected the full python process at the web server
> (it's a
> > Django app) & all user sessions. Is there a way to generate
> dates for a
> > given locale without setlocale?
> >
> >
> > Thanks a lot in advance!
> > Udi
>
> One of the lookups django does to determine the current language is
> looking in the session for the key "django_language" [1] (this
> allows a
> specific language for each user).
>
> I see that you're using the set_language view (which updates the
> django_language var), so wheres the problem ? I've already
> translated
> the date and month names in Django, can't you reuse them (e.g.
> in the
> templates using the specific date filter) ?
>
> Note that the above behavior (setting and submitting the form in js)
> prevents search engines from indexing the other language pages.
>
> BTW, lazy loading of translations might be problematic, if
> that's the
> case (and only if thats the case), try to minimize the usage of them
> (e.g ugetgtext_lazy).
>
>
> [1]
> http://www.djangoproject.com/documentation/i18n/#how-django-discovers-language-preference
>
> Cheers
> --
> Meir Kriheli
> http://mksoft.co.il
>
>
>
More information about the Python-il
mailing list