line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- |
3
|
|
|
|
|
|
|
# vim:ts=8:sw=2:et:sta:sts=2 |
4
|
|
|
|
|
|
|
######### |
5
|
|
|
|
|
|
|
# Author: rmp |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
package ClearPress::Localize; |
8
|
5
|
|
|
5
|
|
38
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
171
|
|
9
|
5
|
|
|
5
|
|
36
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
190
|
|
10
|
5
|
|
|
5
|
|
36
|
use base qw(Locale::Maketext); |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
2002
|
|
11
|
5
|
|
|
5
|
|
63660
|
use HTTP::ClientDetect::Language; |
|
5
|
|
|
|
|
1274196
|
|
|
5
|
|
|
|
|
280
|
|
12
|
|
|
|
|
|
|
use Locale::Maketext::Lexicon { |
13
|
5
|
|
|
|
|
79
|
_auto => 1, |
14
|
|
|
|
|
|
|
_style => 'gettext', |
15
|
5
|
|
|
5
|
|
2295
|
}; |
|
5
|
|
|
|
|
16951
|
|
16
|
5
|
|
|
5
|
|
492
|
use Carp; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
1716
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = q[477.1.4]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
21
|
80
|
|
|
80
|
1
|
1624
|
my ($class, $locales) = @_; |
22
|
80
|
|
|
|
|
612
|
Locale::Maketext::Lexicon->import($locales); |
23
|
80
|
|
|
|
|
27392
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub lang { |
27
|
0
|
|
|
0
|
1
|
|
my $lang_detect = HTTP::ClientDetect::Language->new(server_default => 'en_GB'); |
28
|
|
|
|
|
|
|
my $req = { |
29
|
|
|
|
|
|
|
accept_language => $ENV{HTTP_ACCEPT_LANGUAGE}, |
30
|
0
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $sym = \%ClearPress::request::; |
33
|
0
|
0
|
|
|
|
|
if(!exists $sym->{accept_language}) { |
34
|
0
|
|
|
0
|
|
|
*ClearPress::request::accept_language = sub { my $self = shift; return $self->{accept_language}; }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
bless $req, 'ClearPress::request'; |
38
|
0
|
|
|
|
|
|
my $lang = $lang_detect->language($req); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# if($lang) { |
41
|
|
|
|
|
|
|
# carp qq[Detected $lang from $ENV{HTTP_ACCEPT_LANGUAGE}]; |
42
|
|
|
|
|
|
|
# } |
43
|
0
|
|
|
|
|
|
return $lang; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub localizer { |
47
|
0
|
|
|
0
|
1
|
|
my ($class, $lang) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
0
|
|
|
|
my $lh = __PACKAGE__->get_handle($lang || __PACKAGE__->lang()); |
50
|
0
|
0
|
|
|
|
|
if(!$lh) { |
51
|
0
|
|
|
|
|
|
carp qq[Could not construct localizer for $lang]; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
return $lh; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |