This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale.
| 571 | |
| 572 | |
| 573 | class LocaleTextCalendar(TextCalendar): |
| 574 | """ |
| 575 | This class can be passed a locale name in the constructor and will return |
| 576 | month and weekday names in the specified locale. |
| 577 | """ |
| 578 | |
| 579 | def __init__(self, firstweekday=0, locale=None): |
| 580 | TextCalendar.__init__(self, firstweekday) |
| 581 | if locale is None: |
| 582 | locale = _get_default_locale() |
| 583 | self.locale = locale |
| 584 | |
| 585 | def formatweekday(self, day, width): |
| 586 | with different_locale(self.locale): |
| 587 | return super().formatweekday(day, width) |
| 588 | |
| 589 | def formatmonthname(self, theyear, themonth, width, withyear=True): |
| 590 | with different_locale(self.locale): |
| 591 | return super().formatmonthname(theyear, themonth, width, withyear) |
| 592 | |
| 593 | |
| 594 | class LocaleHTMLCalendar(HTMLCalendar): |