-
Notifications
You must be signed in to change notification settings - Fork 3
/
AcceptLang-v1
50 lines (36 loc) · 1.14 KB
/
AcceptLang-v1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package AcceptLang; # vim:ft=perl:
# available languages and order
my @langs = ('de', 'en');
# default lang if no requested language is available
my $defaultlang = 'en';
sub start {
1;
}
sub filter {
my $self = shift;
my ($files, $others) = @_;
my $acceptlang = $ENV{'HTTP_ACCEPT_LANGUAGE'} ? $ENV{'HTTP_ACCEPT_LANGUAGE'} : $defaultlang;
my @order = parse($acceptlang, @langs);
$blosxom::blog_language = $order[0];
foreach (keys %$files) {
delete $files->{$_} unless (
/^[^.]+\.$order[0]\.$blosxom::file_extension$/ or
/^[^.]+\.$blosxom::file_extension$/
);
}
};
sub parse {
my ($acceptlang, @langs) = @_;
# dumb parsing, good enough for a first start
#my (@order) = $acceptlang =~ /^(?:\s*([^,;]+)[^,]*,)*\s*([^,;]+)[^,]*$/;
# doesn't work -- for now only take the first entry
my (@order) = $acceptlang =~ /^\s*([^,;]+)/;
my $langs = join('|', @langs);
return grep { /^$langs$/ } @order;
}
1;
__END__
use Data::Dumper;
open FOO, ">/tmp/blaaah" or die "$0: can't write to /tmp/blaaah: $!";
print FOO Dumper(\@_, \@order);
close FOO;