NetSDS/Translate.pm

filter: Statementstmt 75.7% 25 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 77.7% 35 / 45 CC 1 SCAR 1.8
CC
1
Cov
76%
new
2.0
translate
2.0
BEGIN
1.0
CRAP 1.2
« NetSDS/Class/Abstract.pm ↑ Summary NetSDS/EDR.pm »
1 #===============================================================================
2 #
3 # FILE: Translate.pm
4 #
5 # DESCRIPTION: Gettext wrapper
6 #
7 # AUTHOR: Michael Bochkaryov (Rattler), <misha@rattler.kiev.ua>
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<NetSDS::Translate> module provides API to gettext translation subsystem
30  
31 =cut
32  
33 package NetSDS::Translate;
34  
35 2 ▶use 5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Locale::gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use NetSDS::Const;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 2 ▶use base 'NetSDS::Class::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 2 ▶use version; our $VERSION = '1.301';
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 #===============================================================================
48 #
49  
50 =head1 CLASS API
51  
52 =over
53  
54 =item B<new(%params)> - class constructor
55  
56 my $trans = NetSDS::Translate->new(
57 lang => 'ru',
58 domain => 'NetSDS-IVR',
59 );
60  
61 =cut
62  
63 #-----------------------------------------------------------------------
64 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
65  
66 0 my ( $class, %params ) = @_;
67  
68 # FIXME - this should be configurable option
69 0 my %locale = (
70 ru => 'ru_RU.UTF-8',
71 en => 'en_US.UTF-8',
72 ua => 'ua_UK.UTF-8',
73 );
74  
75 0 my $self = $class->SUPER::new(
76 lang => DEFAULT_LANG,
77 domain => 'NetSDS',
78 %params,
79 );
80  
81 # Initialize proper locale
82 0 setlocale( LC_MESSAGES, $locale{$self->{lang}} );
83 0 $self->{translator} = Locale::gettext->domain($self->{domain});
84  
85 0 return $self;
86  
87 }
88  
89 #***********************************************************************
90  
91 =item B<translate($string)> - translate string
92  
93 Return translated string.
94  
95 print $trans->translate("All ok");
96  
97 =cut
98  
99 #-----------------------------------------------------------------------
100  
101 0 ▶sub translate {
Subroutine translate: not called CC=1 SCAR=6.9
Pod documented
102  
103 0 my ( $self, $str ) = @_;
104  
105 0 return $self->{translator}->get($str);
106  
107 }
108  
109 2 1;
110  
111 __END__
« NetSDS/Class/Abstract.pm ↑ Summary NetSDS/EDR.pm »