Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar: day/month names in specific locale

Tags:

I am playing with Python's calendar module that's in the standard library. Basically I need a list of all days of a month, like so:

>>> import calendar >>> calobject = calendar.monthcalendar(2012, 10) >>> print calobject [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, 0, 0, 0, 0]] 

Now what I also need are the names of the months and days in a specific locale. I didn't find a way to get these from the calobject itself - but I was able to get them like so:

>>> import calendar >>> calobject = calendar.LocaleTextCalendar(calendar.MONDAY, 'de_DE') >>> calobject.formatmonth(2012, 10) '    Oktober 2012\nMo Di Mi Do Fr Sa So\n 1  2  3  4  5  6  7\n 8  9 10 11 12 13 14\n15 16 17 18 19 20 21\n22 23 24 25 26 27 28\n29 30 31\n' 

So Oktober is the de_DE name for october. Fine. The information must be there. I'm wondering if I can access that month name somehow on a plain calendar object instead of a calendar.LocaleTextCalendar object. The first example (with the list) is really what I need and I don't like the idea to create two calendar objects to get localized names.

Anyone got a smart idea?

like image 581
Daniel Avatar asked Oct 23 '12 19:10

Daniel


People also ask

Can I localize the calendar for a different language?

You can tailor the calendar for certain languages (aka “locales”). The locale setting it the most important, as it sets the defaults of many other options at the same time. The locale and locales options allow you to localize certain aspects of the calendar:

How do I load a calendar with a specific locale?

If you are using an ES6 build system and want to load a specific locale, do something like this: import { Calendar } from '@fullcalendar/core'; import esLocale from '@fullcalendar/core/locales/es'; ... let calendar = new Calendar(calendarEl, { locale: esLocale }); ...

What is the most important option in the calendar settings?

The locale setting it the most important, as it sets the defaults of many other options at the same time. The locale and locales options allow you to localize certain aspects of the calendar:

What is the direction of the calendar?

The direction that elements in the calendar are rendered. Either left-to-right or right-to-left. The day that each week begins.


1 Answers

Ha! Found an easy way to get localized day/month names:

>>> import locale >>> locale.setlocale(locale.LC_ALL, 'de_DE') 'de_DE' >>> import calendar >>> calendar.month_name[10] 'Oktober' >>> calendar.day_name[1] 'Dienstag' 
like image 73
Daniel Avatar answered Oct 23 '22 13:10

Daniel