line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ado::I18n; |
2
|
23
|
|
|
23
|
|
14862
|
use Mojo::Base 'Locale::Maketext'; |
|
23
|
|
|
|
|
42
|
|
|
23
|
|
|
|
|
183
|
|
3
|
|
|
|
|
|
|
our %Lexicon = (_AUTO => 1); ##no critic(ProhibitPackageVars) |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub get_handle { |
6
|
109
|
|
|
109
|
1
|
249
|
my ($class, $language, $c, $config) = @_; |
7
|
109
|
|
|
|
|
189
|
state $loaded = {}; |
8
|
|
|
|
|
|
|
|
9
|
109
|
|
|
|
|
175
|
my $self = $class->SUPER::get_handle($language, @{$$config{languages}}); |
|
109
|
|
|
|
|
1058
|
|
10
|
|
|
|
|
|
|
$self->_load_messages_from_db($c->dbix, $$config{default_language}) |
11
|
109
|
100
|
|
|
|
44247
|
unless $loaded->{$language}; |
12
|
109
|
|
|
|
|
312
|
$loaded->{$language} = 1; |
13
|
109
|
|
|
|
|
505
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _load_messages_from_db { |
17
|
20
|
|
|
20
|
|
40332
|
my ($self, $dbix, $default) = @_; |
18
|
20
|
|
|
|
|
58
|
my $SQL = <<'SQL'; |
19
|
|
|
|
|
|
|
SELECT d.msgid AS msgid,( |
20
|
|
|
|
|
|
|
CASE |
21
|
|
|
|
|
|
|
WHEN cl.msgstr IS NULL OR cl.msgstr='' |
22
|
|
|
|
|
|
|
THEN d.msgstr |
23
|
|
|
|
|
|
|
ELSE cl.msgstr |
24
|
|
|
|
|
|
|
END) AS msgstr |
25
|
|
|
|
|
|
|
-- default language |
26
|
|
|
|
|
|
|
FROM (SELECT msgid, msgstr FROM i18n WHERE lang=?) d |
27
|
|
|
|
|
|
|
-- current language |
28
|
|
|
|
|
|
|
LEFT JOIN (SELECT msgid, msgstr FROM i18n WHERE lang=?) cl |
29
|
|
|
|
|
|
|
ON (cl.msgid=d.msgid) |
30
|
|
|
|
|
|
|
SQL |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#get messages from database |
33
|
20
|
|
|
|
|
240
|
my %lex = $dbix->query($SQL, $default, $self->language_tag)->map; |
34
|
|
|
|
|
|
|
{ |
35
|
23
|
|
|
23
|
|
146954
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
23
|
|
|
|
|
52
|
|
|
23
|
|
|
|
|
2414
|
|
|
20
|
|
|
|
|
8119
|
|
36
|
20
|
|
|
|
|
2181
|
my $class_lex = ref($self) . '::Lexicon'; |
37
|
20
|
|
|
|
|
47
|
%{$class_lex} = (%{$class_lex}, %lex); |
|
20
|
|
|
|
|
539
|
|
|
20
|
|
|
|
|
311
|
|
38
|
|
|
|
|
|
|
}; |
39
|
20
|
|
|
|
|
184
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding utf8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Ado::I18n - Languages' lexicons and handle namespace |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This class is used to instantiate the language handle in L. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This class inherits all methods from L and defines the |
59
|
|
|
|
|
|
|
following ones. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 get_handle |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Constructor |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $i18n = Ado::I18n->get_handle('bg', $c, $config); |
66
|
|
|
|
|
|
|
$i18n->maketext('hello',$user->name); # Здравей, Красимир Беров |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L, L, L, |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SPONSORS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The original author |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Красимир Беров (Krasimir Berov) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright 2014 Красимир Беров (Krasimir Berov). |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or |
86
|
|
|
|
|
|
|
modify it under the terms of the |
87
|
|
|
|
|
|
|
GNU Lesser General Public License v3 (LGPL-3.0). |
88
|
|
|
|
|
|
|
You may copy, distribute and modify the software provided that |
89
|
|
|
|
|
|
|
modifications are open source. However, software that includes |
90
|
|
|
|
|
|
|
the license may release under a different license. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See http://opensource.org/licenses/lgpl-3.0.html for more information. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|