line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# FILE: Translate.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION: Gettext wrapper |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# AUTHOR: Michael Bochkaryov (Rattler), |
8
|
|
|
|
|
|
|
# COMPANY: Net.Style |
9
|
|
|
|
|
|
|
# CREATED: 03.08.2009 13:34:51 UTC |
10
|
|
|
|
|
|
|
#=============================================================================== |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
NetSDS::Translate - simple API to gettext |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use NetSDS::Translate; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $trans = NetSDS::Translate->new( |
21
|
|
|
|
|
|
|
lang => 'ru', |
22
|
|
|
|
|
|
|
domain => 'NetSDS-IVR', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
print $trans->translate("Detect CallerID"); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
C module provides API to gettext translation subsystem |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package NetSDS::Translate; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
|
5689
|
use 5.8.0; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
94
|
|
36
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
37
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
1614
|
use POSIX; |
|
2
|
|
|
|
|
23418
|
|
|
2
|
|
|
|
|
13
|
|
40
|
2
|
|
|
2
|
|
8566
|
use Locale::gettext; |
|
2
|
|
|
|
|
34082
|
|
|
2
|
|
|
|
|
6820
|
|
41
|
2
|
|
|
2
|
|
520
|
use NetSDS::Const; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
194
|
|
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
2
|
|
13
|
use base 'NetSDS::Class::Abstract'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
712
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use version; our $VERSION = '1.301'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#=============================================================================== |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 CLASS API |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item B - class constructor |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $trans = NetSDS::Translate->new( |
57
|
|
|
|
|
|
|
lang => 'ru', |
58
|
|
|
|
|
|
|
domain => 'NetSDS-IVR', |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
64
|
|
|
|
|
|
|
sub new { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my ( $class, %params ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# FIXME - this should be configurable option |
69
|
|
|
|
|
|
|
my %locale = ( |
70
|
|
|
|
|
|
|
ru => 'ru_RU.UTF-8', |
71
|
|
|
|
|
|
|
en => 'en_US.UTF-8', |
72
|
|
|
|
|
|
|
ua => 'ua_UK.UTF-8', |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $self = $class->SUPER::new( |
76
|
|
|
|
|
|
|
lang => DEFAULT_LANG, |
77
|
|
|
|
|
|
|
domain => 'NetSDS', |
78
|
|
|
|
|
|
|
%params, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Initialize proper locale |
82
|
|
|
|
|
|
|
setlocale( LC_MESSAGES, $locale{$self->{lang}} ); |
83
|
|
|
|
|
|
|
$self->{translator} = Locale::gettext->domain($self->{domain}); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $self; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#*********************************************************************** |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item B - translate string |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Return translated string. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
print $trans->translate("All ok"); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub translate { |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ( $self, $str ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return $self->{translator}->get($str); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |