Commits

Jun Omae committed b7b3e20

1.0dev: Workaround the first week day in date picker using `babel.core.LOCALE_ALIASES` if the locale has no territory

A part of #10757.

  • Participants
  • Parent commits ac6f9f3
  • Branches trunk

Comments (0)

Files changed (2)

trac/util/datefmt.py

 
 try:
     import babel
+    from babel import Locale
+    from babel.core import LOCALE_ALIASES
     from babel.dates import format_datetime as babel_format_datetime, \
                             format_date as babel_format_date, \
                             format_time as babel_format_time, \
             if zone == '+0000' else zone[:-2] + ':' + zone[-2:]
             for zone in sorted(zones, key=lambda tz: int(tz))]
 
+def get_first_week_day_jquery_ui(req):
+    """Get first week day for jQuery date picker"""
+    locale = req.lc_time
+    if locale == 'iso8601':
+        return 1 # Monday
+    if babel and locale:
+        if not locale.territory and locale.language in LOCALE_ALIASES:
+            locale = Locale.parse(LOCALE_ALIASES[locale.language])
+        return (locale.first_week_day + 1) % 7
+    return 0 # Sunday
+
 def is_24_hours(locale):
     """Returns `True` for 24 hour time formats."""
     if locale == 'iso8601':

trac/web/chrome.py

 from trac.util.text import pretty_size, obfuscate_email_address, \
                            shorten_line, unicode_quote_plus, to_unicode, \
                            javascript_quote, exception_to_unicode
-from trac.util.datefmt import pretty_timedelta, format_datetime, format_date, \
-                              format_time, from_utimestamp, http_date, utc, \
-                              get_date_format_jquery_ui, is_24_hours, \
-                              get_time_format_jquery_ui, user_time, \
-                              get_month_names_jquery_ui, \
-                              get_day_names_jquery_ui, \
-                              get_timezone_list_jquery_ui
+from trac.util.datefmt import (
+    pretty_timedelta, format_datetime, format_date, format_time,
+    from_utimestamp, http_date, utc, get_date_format_jquery_ui, is_24_hours,
+    get_time_format_jquery_ui, user_time, get_month_names_jquery_ui,
+    get_day_names_jquery_ui, get_timezone_list_jquery_ui,
+    get_first_week_day_jquery_ui)
 from trac.util.translation import _, get_available_locales
 from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound
 from trac.web.href import Href
                             or 'common/css/jquery-ui/jquery-ui.css')
         add_script(req, 'common/js/jquery-ui-addons.js')
         add_stylesheet(req, 'common/css/jquery-ui-addons.css')
-        first_day = (req.locale.first_week_day + 1) % 7 \
-                    if req.locale and req.locale.territory else 0
         is_iso8601 = req.lc_time == 'iso8601'
         add_script_data(req, jquery_ui={
             'month_names': get_month_names_jquery_ui(req),
             'date_format': get_date_format_jquery_ui(req.lc_time),
             'time_format': get_time_format_jquery_ui(req.lc_time),
             'ampm': not is_24_hours(req.lc_time),
-            'first_week_day': first_day,
+            'first_week_day': get_first_week_day_jquery_ui(req),
             'timepicker_separator': 'T' if is_iso8601 else ' ',
             'show_timezone': is_iso8601,
             'timezone_list': get_timezone_list_jquery_ui() \