| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Message::Locale; |
|
2
|
1
|
|
|
1
|
|
25226
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
|
7
|
|
|
|
|
|
|
my ($self, $app, $conf) = @_; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$conf->{default_message} ||= ''; |
|
10
|
|
|
|
|
|
|
$conf->{locale} ||= 'en'; |
|
11
|
|
|
|
|
|
|
$conf->{file} ||= 'locale.conf'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $messages = $app->plugin('Config', { file => $conf->{file} } ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper ( set_locale => sub { |
|
16
|
|
|
|
|
|
|
my ($c, $loc,) = @_; |
|
17
|
|
|
|
|
|
|
$conf->{locale} = $loc ? $loc : 'en'; |
|
18
|
|
|
|
|
|
|
}); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$app->helper ( locale => sub { |
|
21
|
|
|
|
|
|
|
my ($c, $key, $group,) = @_; |
|
22
|
|
|
|
|
|
|
unless ( $key ) { |
|
23
|
|
|
|
|
|
|
warn 'key is undefined or incorrenct.'; |
|
24
|
|
|
|
|
|
|
return $conf->{default_message}; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
$group ||= 'common'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( exists $messages->{$group}->{$key}->{$conf->{locale}} ) { |
|
29
|
|
|
|
|
|
|
$messages->{$group}->{$key}->{$conf->{locale}}; |
|
30
|
|
|
|
|
|
|
} elsif ( exists $messages->{'common'}->{$key}->{$conf->{locale}} ) { |
|
31
|
|
|
|
|
|
|
$messages->{'common'}->{$key}->{$conf->{locale}} |
|
32
|
|
|
|
|
|
|
} else { |
|
33
|
|
|
|
|
|
|
$conf->{default_message}; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
}); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
|
39
|
|
|
|
|
|
|
__END__ |