Changeset ac3af33 in OpenWorkouts-current for ow/utilities.py


Ignore:
Timestamp:
Feb 26, 2019, 11:54:11 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
68d00f5
Parents:
e171dc2
Message:

(#69) Ensure month and weekday names are translated.

This is a dirty hack, which basically uses static strings marked for
translation within openworkouts, instead of relying on the python
locale and calendar translations.

We need this hack, as in some operating systems (OpenBSD), using
locale.setlocale() does not make any difference when using calendar.month_name
(names appear always in the system locale/LANG).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/utilities.py

    re171dc2 rac3af33  
    282282
    283283
     284def get_month_names():
     285    """
     286    Return a list with the names of the months, marked for translation.
     287
     288    This should be done automatically by the calendar module:
     289
     290    >>> import calendar
     291    >>> calendar.month_name[1]
     292    'January'
     293    >>>
     294
     295    But even trying setting the proper locale (using locale.setlocale()),
     296    in some operating systems the names are not translated (OpenBSD).
     297
     298    So, for now, we use this dirty trick
     299    """
     300    return [
     301        '',
     302        _('January'),
     303        _('February'),
     304        _('March'),
     305        _('April'),
     306        _('May'),
     307        _('June'),
     308        _('July'),
     309        _('August'),
     310        _('September'),
     311        _('October'),
     312        _('November'),
     313        _('December')
     314    ]
     315
     316
     317def get_week_day_names():
     318    """
     319    Return a list with the names of the week days, marked for translation.
     320
     321    As with get_month_names(), this is a dirty workaround for some locale
     322    problem in some operating systems
     323    """
     324    return [
     325        _('Monday'),
     326        _('Tuesday'),
     327        _('Wednesday'),
     328        _('Thursday'),
     329        _('Friday'),
     330        _('Saturday'),
     331        _('Sunday'),
     332    ]
     333
     334
    284335def part_of_day(dt):
    285336    """
Note: See TracChangeset for help on using the changeset viewer.