| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Leyland::Localizer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Wrapper for the Locale::Wolowitz localization system for Leyland apps |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
15
|
use Moo; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
18
|
|
|
6
|
2
|
|
|
2
|
|
966
|
use namespace::clean; |
|
|
2
|
|
|
|
|
17
|
|
|
|
2
|
|
|
|
|
24
|
|
|
7
|
2
|
|
|
2
|
|
2969
|
use Locale::Wolowitz; |
|
|
2
|
|
|
|
|
57656
|
|
|
|
2
|
|
|
|
|
521
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Leyland::Localizer - Wrapper for the Locale::Wolowitz localization system for Leyland apps |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# in your app's main package |
|
16
|
|
|
|
|
|
|
sub setup { |
|
17
|
|
|
|
|
|
|
return { |
|
18
|
|
|
|
|
|
|
... |
|
19
|
|
|
|
|
|
|
locales => '/path/to/myapp/locales', |
|
20
|
|
|
|
|
|
|
... |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# in your controllers |
|
25
|
|
|
|
|
|
|
$c->set_lang('es'); # use Spanish when responding, possibly because that's what the client wants |
|
26
|
|
|
|
|
|
|
$c->loc('Hello %1', $c->params->{name}); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# in your views (assuming you're using L): |
|
29
|
|
|
|
|
|
|
[== $c->loc('Hello %1', $c->params->{name}) =] |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module provides Leyland applications with simple localization capabilities, |
|
34
|
|
|
|
|
|
|
using L. This does not mean localizing your application |
|
35
|
|
|
|
|
|
|
to the locale of the computer/server on which it is running, but localizing |
|
36
|
|
|
|
|
|
|
your HTTP responses according to your application's client's wishes. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
If, for example, your application is a website provided in two or more |
|
39
|
|
|
|
|
|
|
languages, this module will provide your application with Wolowitz's |
|
40
|
|
|
|
|
|
|
C method, for translating strings into a certain language. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
See the L for more information. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 path |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The path of the directory in which L translation files |
|
49
|
|
|
|
|
|
|
reside. Can be a relative path. This attribute will come from the "locales" |
|
50
|
|
|
|
|
|
|
config option in C. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 w |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The L object used for localization. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 loc( $string, $language, [ @replacements ] ) |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Translates C<$string> into C<$language>, possibly performing some replacements. |
|
61
|
|
|
|
|
|
|
This is just a shortcut for C<< Locale::Wolowitz->loc() >>, so check out |
|
62
|
|
|
|
|
|
|
L for more information. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has 'path' => ( |
|
67
|
|
|
|
|
|
|
is => 'ro', |
|
68
|
|
|
|
|
|
|
isa => sub { die "path must be a scalar" if ref $_[0] }, |
|
69
|
|
|
|
|
|
|
required => 1 |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has 'w' => ( |
|
73
|
|
|
|
|
|
|
is => 'ro', |
|
74
|
|
|
|
|
|
|
isa => sub { die "w must be a Locale::Wolowitz object" unless ref $_[0] && ref $_[0] eq 'Locale::Wolowitz' }, |
|
75
|
|
|
|
|
|
|
writer => '_set_w', |
|
76
|
|
|
|
|
|
|
handles => ['loc'] |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The following methods are only to be used internally. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 BUILD() |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub BUILD { |
|
88
|
0
|
|
|
0
|
1
|
|
$_[0]->_set_w(Locale::Wolowitz->new($_[0]->path)); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Ido Perlmuter, C<< >> |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 BUGS |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
98
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
99
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SUPPORT |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
perldoc Leyland::Localizer |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
You can also look for information at: |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * Search CPAN |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright 2010-2014 Ido Perlmuter. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
134
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
135
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |