]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/Encoding_problem_in_calendar_plugin.mdwn
Clearer (I hope) bug report
[ikiwiki.git] / doc / bugs / Encoding_problem_in_calendar_plugin.mdwn
1 Hello,
2
3 I studied this [[guy's problem|forum/Encoding_problem_in_french_with_ikiwiki-calendar]] and I propose here a (dirty) hack to correct it.
4
5 Bug summary: when using the [[calendar plugin|plugins/calendar]] in French (`LANG=fr_FR.UTF-8`), "Décembre" (French for "December") is rendered as "Décembre".
6
7 I managed to track this problem down to an encoding problem of `POSIX::strftime` in `Ikiwiki/Plugin/calendar.pm`. I used [[this guy's solution|http://www.perlmonks.org/?node_id=857018]] to solve the problem (the diff is printed below).
8
9 The problem is that I do not know Perl, encoding is one of the thing I would be happy not to dive into, and it is the first time I contribute to Ikiwiki: I copied and made a few changes to the code I found without understanding it. So I am not sure that my code is neat, or works in every situation. Feel free to (help me to) improve it!
10
11 Cheers,    
12 Louis
13
14
15     diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
16     index c7d2b7c..1345939 100644
17     --- a/IkiWiki/Plugin/calendar.pm
18     +++ b/IkiWiki/Plugin/calendar.pm
19     @@ -22,7 +22,14 @@ use warnings;
20      use strict;
21      use IkiWiki 3.00;
22      use Time::Local;
23     -use POSIX ();
24     +
25     +use POSIX qw/setlocale LC_TIME strftime/;
26     +use Encode;
27     +my ($strftime_encoding)= setlocale(LC_TIME)=~m#\.([^@]+)#;
28     +sub strftime_utf8 {
29     +# try to return an utf8 value from strftime
30     +   $strftime_encoding ? Encode::decode($strftime_encoding, &strftime) : &strftime;
31     +}
32      
33      my $time=time;
34      my @now=localtime($time);
35     @@ -123,10 +130,10 @@ sub format_month (@) {
36         }
37      
38         # Find out month names for this, next, and previous months
39     -   my $monthabbrev=POSIX::strftime("%b", @monthstart);
40     -   my $monthname=POSIX::strftime("%B", @monthstart);
41     -   my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900)));
42     -   my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900)));
43     +   my $monthabbrev=strftime_utf8("%b", @monthstart);
44     +   my $monthname=strftime_utf8("%B", @monthstart);
45     +   my $pmonthname=strftime_utf8("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900)));
46     +   my $nmonthname=strftime_utf8("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900)));
47      
48         my $archivebase = 'archives';
49         $archivebase = $config{archivebase} if defined $config{archivebase};
50     @@ -182,7 +189,7 @@ EOF
51         my %dowabbr;
52         for my $dow ($week_start_day..$week_start_day+6) {
53                 my @day=localtime(timelocal(0,0,0,$start_day++,$params{month}-1,$params{year}-1900));
54     -           my $downame = POSIX::strftime("%A", @day);
55     +           my $downame = strftime_utf8("%A", @day);
56                 my $dowabbr = substr($downame, 0, 1);
57                 $downame{$dow % 7}=$downame;
58                 $dowabbr{$dow % 7}=$dowabbr;
59     @@ -329,8 +336,8 @@ EOF
60         for (my $month = 1; $month <= 12; $month++) {
61                 my @day=localtime(timelocal(0,0,0,15,$month-1,$params{year}-1900));
62                 my $murl;
63     -           my $monthname = POSIX::strftime("%B", @day);
64     -           my $monthabbr = POSIX::strftime("%b", @day);
65     +           my $monthname = strftime_utf8("%B", @day);
66     +           my $monthabbr = strftime_utf8("%b", @day);
67                 $calendar.=qq{\t<tr>\n}  if ($month % $params{months_per_row} == 1);
68                 my $tag;
69                 my $mtag=sprintf("%02d", $month);