language

33 views
Skip to first unread message

armagan

unread,
Jun 26, 2012, 11:59:44 AM6/26/12
to django...@googlegroups.com
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?

kenneth gonsalves

unread,
Jun 26, 2012, 12:09:16 PM6/26/12
to django...@googlegroups.com
On Tue, 2012-06-26 at 04:59 -0700, armagan wrote:
> 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.

this may help you:
https://docs.djangoproject.com/en/dev/topics/i18n/
--
regards
Kenneth Gonsalves

Masklinn

unread,
Jun 26, 2012, 12:17:49 PM6/26/12
to django...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages