Modify

Opened 11 years ago

Closed 11 years ago

#10993 closed defect (fixed)

Day names header is garbled with `Accept-Language: ja`

Reported by: Jun Omae Owned by: Steffen Hoffmann
Priority: normal Component: WikiCalendarMacro
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description (last modified by Jun Omae)

When browser sends Accept-Language: ja, WikiCalendarMacro renders garbled header in the calendar.

Request headers:

GET /wiki/SandBox/WikiCalendarMacro HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ja,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Cookie: auth_sess=3bbf3b909d6b22263a27589ac10a5b982694efd3; trac_form_token=af700c16ee5b5954f9430684; trac_auth=826fd3482f6220360de2c655d04e8fda
Authorization: Digest username="foobar", realm="auth", nonce="571817734d427a974703a57ce65da867", uri="/wiki/SandBox/WikiCalendarMacro", response="6f87d9dd77b4351e53f0c96408efc4de", qop=auth, nc=00000152, cnonce="17b7a21e4253ce7a"
Connection: keep-alive

Response headers:

HTTP/1.1 200 OK
Server: tracd/0.12.5 Python/2.4.3
Date: Sun, 31 Mar 2013 06:24:20 GMT
Cache-Control: must-revalidate
Expires: Fri, 01 Jan 1999 00:00:00 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 14444

From trac.log;

...
03:15:43 PM Trac[util] DEBUG: args: ('wiki', u'SandBox/WikiCalendarMacro')
03:15:43 PM Trac[util] DEBUG: prefetch: 0 rows
03:15:43 PM Trac[formatter] DEBUG: Executing Wiki macro WikiCalendar by provider <wikicalendar.macros.WikiCalendarMacros object at 0xa96340c>
15��15ʬ43�� Trac[macros] DEBUG: Locale setting for calendar: ja_JP.eucJP
...

At least, should use ja_JP.UTF8 instead of ja_JP.eucJP.

Attachments (1)

ja-WikiCalendarMacro.png (3.4 KB) - added by Jun Omae 11 years ago.

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by Jun Omae

Attachment: ja-WikiCalendarMacro.png added

comment:1 Changed 11 years ago by Jun Omae

Description: modified (diff)

comment:2 Changed 11 years ago by Jun Omae

locale.getlocale() returns language code, encoding as tuple. The encoding is able to use for unicode decoding.

  • wikicalendar/macros.py

     
    496497        except AttributeError:
    497498            # Available since in Trac 0.12 .
    498499            loc_req = None
     500        loc_prop = loc_encoding = None
    499501        if loc_req:
    500502            loc = locale.getlocale()
    501503            loc_prop = locale.normalize(loc_req)
     
    508510                    locale.setlocale(locale.LC_TIME, loc_prop)
    509511                except locale.Error:
    510512                    loc_prop = None
     513            loc_encoding = locale.getlocale(locale.LC_TIME)[1]
    511514            self.env.log.debug('Locale setting for calendar: ' + str(loc_prop))
    512515
    513516        # Finally building the output
     
    550553        heading = tag.tr()
    551554        heading(align='center')
    552555
    553         for day in calendar.weekheader(2).split()[:-2]:
    554             col = tag.th(to_unicode(day))
    555             col(class_='workday', scope='col')
     556        for idx, day in enumerate(calendar.day_abbr):
     557            day = to_unicode(day, charset=loc_encoding)
     558            col = tag.th(day[:2])
     559            col(class_=('workday', 'weekend')[idx == 6], scope='col')
    556560            heading(col)
    557         for day in calendar.weekheader(2).split()[-2:]:
    558             col = tag.th(to_unicode(day))
    559             col(class_='weekend', scope='col')
    560             heading(col)
    561561
    562562        heading = buff(tag.thead(heading))
    563563

comment:3 in reply to:  2 Changed 11 years ago by Steffen Hoffmann

Replying to jun66j5:

locale.getlocale() returns language code, encoding as tuple. The encoding is able to use for unicode decoding.

Thanks for the suggestion, even if #10992 suggests it might be only an intermediate solution.

Regarding the calendar header constructor I've felt the old code was sub-optimal, but couldn't do better. Using a test result as index looks much more elegant indeed.

You proposed patch made me think about another possible aspect of customization: number of workdays per week. It must have felt as natural to you to set weekend == Sunday as it does to me to set it according to the two-days-weekend like done by the replaced code. Number of weekdays matters especially for ticket calendar due to different column widths. This is in CSS, hence it's not so flexible.

comment:4 Changed 11 years ago by Steffen Hoffmann

(In [12847]) WikiCalendarMacro: Use encoding to get proper weekday headers, refs #10992 and #10993.

Follow-up on [11557], although it might be yet another intermediate step as suggested by #10992. Thanks again to Jun Omae for the patch code and related explainations on the issue.

comment:5 Changed 11 years ago by Steffen Hoffmann

(In [12951]) WikiCalendarMacro: Switch from Python core modules calendar and locale towards using Babel by default, refs #10992 and #10993.

This is the bare minimum of changes, that don't break code, but turn Babel into an undeclared, strict requirement so far. I'll fix that later. Starting to remove class attribute variables for becoming thread-safe again.

comment:6 Changed 11 years ago by Steffen Hoffmann

Resolution: fixed
Status: newclosed

(In [12991]) WikiCalendarMacro: Releasing current, tested macro package as final product, closes #7639, #8175, #9718, #10991, #10992 and #10993.

Special thanks to Jun Omae for pushing development by testing and providing valuable hints in our discussion about utilizing Babel for better localization and for making macro execution thread-safe as well.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Steffen Hoffmann.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.