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
|
|
49
|
use strict; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
197
|
|
9
|
5
|
|
|
5
|
|
37
|
use warnings; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
219
|
|
10
|
5
|
|
|
5
|
|
37
|
use base qw(Locale::Maketext); |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
2301
|
|
11
|
5
|
|
|
5
|
|
73234
|
use HTTP::ClientDetect::Language; |
|
5
|
|
|
|
|
1754465
|
|
|
5
|
|
|
|
|
243
|
|
12
|
|
|
|
|
|
|
use Locale::Maketext::Lexicon { |
13
|
5
|
|
|
|
|
68
|
_auto => 1, |
14
|
|
|
|
|
|
|
_style => 'gettext', |
15
|
5
|
|
|
5
|
|
2327
|
}; |
|
5
|
|
|
|
|
16249
|
|
16
|
5
|
|
|
5
|
|
499
|
use Carp; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
1858
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = q[477.1.2]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
21
|
80
|
|
|
80
|
1
|
2066
|
my ($class, $locales) = @_; |
22
|
80
|
|
|
|
|
678
|
Locale::Maketext::Lexicon->import($locales); |
23
|
80
|
|
|
|
|
35620
|
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__ |