Re: language
On 2012-06-26, at 13:59 , armagan wrote:
> Hi,
>
> I'm trying to write the month name from number. I have done. But month's
> name is English. I want to change the name to Turkish.
>
> *In [35]: m = calendar.month_name[3]*
>
> *In [36]: m*
>
> *Out[36]: 'March'*
>
> Can you help me?
That's got nothing to do with Django, FWIW. If you go see the documentation[0]
it says:
> An array that represents the months of the year in the current locale.
How do you set the current locale?
with locale.setlocale:
> http://docs.python.org/library/locale.html?highlight=locale#locale.setlocale
>>> import calendar, locale
>>> calendar.month_name[1]
'January'
>>> locale.setlocale(locale.LC_TIME, 'fr_fr')
'fr_fr'
>>> calendar.month_name[1]
'janvier'
>>> locale.setlocale(locale.LC_TIME, 'tr_TR')
'tr_TR'
>>> calendar.month_name[1]
'Ocak'
I would, however, recommend against that as setlocale is not
thread-safe. Instead, I'd use Babel[1] as it does not require
altering global state:
>>> import babel.dates
>>> babel.dates.get_month_names()[1]
u'January'
>>> babel.dates.get_month_names(locale='fr_fr')[1]
u'janvier'
>>> babel.dates.get_month_names(locale='tr_TR')[1]
u'Ocak'
[0] http://docs.python.org/library/calendar.html?highlight=month_name#calendar.month_name
[1] http://babel.edgewall.org/wiki/ApiDocs/babel.dates#babel.dates:get_month_names
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home