|
Lines 63-68
sub new {
Link Here
|
| 63 |
"$htdocs/$theme/en/includes" |
63 |
"$htdocs/$theme/en/includes" |
| 64 |
], |
64 |
], |
| 65 |
FILTERS => {}, |
65 |
FILTERS => {}, |
|
|
66 |
ENCODING => 'utf8', # templates don't have BOM, see Template::FAQ |
| 66 |
} |
67 |
} |
| 67 |
) or die Template->error(); |
68 |
) or die Template->error(); |
| 68 |
my $self = { |
69 |
my $self = { |
|
Lines 110-163
sub output {
Link Here
|
| 110 |
# and clean any utf8 mess |
111 |
# and clean any utf8 mess |
| 111 |
for my $k ( keys %{ $self->{VARS} } ) { |
112 |
for my $k ( keys %{ $self->{VARS} } ) { |
| 112 |
$vars->{$k} = $self->{VARS}->{$k}; |
113 |
$vars->{$k} = $self->{VARS}->{$k}; |
| 113 |
if (ref($vars->{$k}) eq 'ARRAY'){ |
|
|
| 114 |
utf8_arrayref($vars->{$k}); |
| 115 |
} |
| 116 |
elsif (ref($vars->{$k}) eq 'HASH'){ |
| 117 |
utf8_hashref($vars->{$k}); |
| 118 |
} |
| 119 |
else { |
| 120 |
utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); |
| 121 |
} |
| 122 |
} |
114 |
} |
| 123 |
my $data; |
115 |
my $data; |
| 124 |
# binmode( STDOUT, ":utf8" ); |
|
|
| 125 |
$template->process( $self->filename, $vars, \$data ) |
116 |
$template->process( $self->filename, $vars, \$data ) |
| 126 |
|| die "Template process failed: ", $template->error(); |
117 |
|| die "Template process failed: ", $template->error(); |
| 127 |
return $data; |
118 |
return $data; |
| 128 |
} |
119 |
} |
| 129 |
|
120 |
|
| 130 |
sub utf8_arrayref { |
121 |
|
| 131 |
my $arrayref = shift; |
|
|
| 132 |
foreach my $element (@$arrayref){ |
| 133 |
if (ref($element) eq 'ARRAY'){ |
| 134 |
utf8_arrayref($element); |
| 135 |
next; |
| 136 |
} |
| 137 |
if (ref($element) eq 'HASH'){ |
| 138 |
utf8_hashref($element); |
| 139 |
next; |
| 140 |
} |
| 141 |
utf8::encode($element) if utf8::is_utf8($element); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
sub utf8_hashref { |
| 146 |
my $hashref = shift; |
| 147 |
for my $key (keys %{$hashref}){ |
| 148 |
if (ref($hashref->{$key}) eq 'ARRAY'){ |
| 149 |
utf8_arrayref($hashref->{$key}); |
| 150 |
next; |
| 151 |
} |
| 152 |
if (ref($hashref->{$key}) eq 'HASH'){ |
| 153 |
utf8_hashref($hashref->{$key}); |
| 154 |
next; |
| 155 |
} |
| 156 |
utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
# FIXME - this is a horrible hack to cache |
122 |
# FIXME - this is a horrible hack to cache |
| 162 |
# the current known-good language, temporarily |
123 |
# the current known-good language, temporarily |
| 163 |
# put in place to resolve bug 4403. It is |
124 |
# put in place to resolve bug 4403. It is |