CatalystX/I18N.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 11 / 11 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« CatalystX/I18N/TypeConstraints.pm ↑ Summary
1 # ============================================================================
2 package CatalystX::I18N;
3 # ============================================================================
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = "1.14";
9 1 our $AUTHORITY = 'cpan:MAROS';
10  
11 1 1;
12  
13 =encoding utf8
14  
15 =head1 NAME
16  
17 CatalystX::I18N - Catalyst internationalisation (I18N) framework
18  
19 =head1 SYNOPSIS
20  
21 package MyApp::Catalyst;
22 use strict;
23 use warnings;
24 use Catalyst qw/
25 +CatalystX::I18N::Role::Base
26 +CatalystX::I18N::Role::GetLocale
27 +CatalystX::I18N::Role::DateTime
28 +CatalystX::I18N::Role::Maketext
29 /;
30 # Choose only the roles you need
31 # CatalystX::I18N::Role::All is a convinient shortcut to load all available roles
32
33 # Optionally also load request and response roles (also loaded by CatalystX::I18N::Role::All)
34 use CatalystX::RoleApplicator;
35 __PACKAGE__->apply_request_class_roles(qw/CatalystX::I18N::TraitFor::Request/);
36 __PACKAGE__->apply_response_class_roles(qw/CatalystX::I18N::TraitFor::Response/);
37
38 # Add some I18N configuration
39 __PACKAGE__->config(
40 name => 'MyApp',
41 I18N => {
42 default_locale => 'de_AT',
43 locales => {
44 'de' => {
45 format_date => 'dd.MM.yyyy',
46 format_datetime => 'dd.MM.yyyy HH:mm',
47 },
48 'de_AT' => {
49 inherits => 'de',
50 timezone => 'Europe/Vienna',
51 format_datetime => 'dd.MM.yyyy uma HH\'e\'',
52 },
53 'de_DE' => {
54 inherits => 'de',
55 timezone => 'Europe/Berlin',
56 },
57 }
58 },
59 );
60  
61 Then in your controller classes
62  
63 package MyApp::Catalyst::Controller::Main;
64 use strict;
65 use warnings;
66 use parent qw/Catalyst::Controller/;
67
68 sub auto : Private {
69 my ($self,$c) = @_;
70 $c->get_locale();
71 # Tries to fetch the locale from the folloing sources in the given order
72 # 1. Session
73 # 2. User settings
74 # 3. Browser settings
75 # 4. Client address
76 # 5. Default locale from config
77 }
78
79 sub action : Local {
80 my ($self,$c) = @_;
81
82 $c->stash->{title} = $c->maketext('Hello world!');
83 $c->stash->{location} = $c->i18n_geocode->name;
84 $c->stash->{language} = $c->language;
85 $c->stash->{localtime} = $c->i18n_datetime_format_date->format_datetime(DateTime->now);
86 }
87  
88 If you want to load all available roles and traits you can use
89 L<CatalystX::I18N::Role::All> as a shortcut.
90  
91 package MyApp::Catalyst;
92 use strict;
93 use warnings;
94 use Catalyst qw/
95 +CatalystX::I18N::Role::All
96 /;
97  
98 =head1 DESCRIPTION
99  
100 CatalystX::I18N provides a comprehensive toolset for internationalisation
101 (I18N) and localisation (L10N) of catalyst applications. This distribution
102 consists of several modules that are designed to integrate seamlessly, but
103 can be run idependently or replaced easily if necessary.
104  
105 =over
106  
107 =item * L<CatalystX::I18N::Role::Base>
108  
109 Basic I18N role that glues everything toghether.
110  
111 =item * L<CatalystX::I18N::Role::Maketext>
112  
113 Localize text via L<Locale::Maketext>. Prefered over
114 L<CatalystX::I18N::Role::DataLocalize>
115  
116 =item * L<CatalystX::I18N::Role::DataLocalize>
117  
118 Localize text via L<Data::Localize>. Alternative to
119 L<CatalystX::I18N::Role::Maketext>
120  
121 =item * L<CatalystX::I18N::Role::PosixLocale>
122  
123 Sets the POSIX locale
124  
125 =item * L<CatalystX::I18N::Role::DateTime>
126  
127 Methods for localising date and time information.
128  
129 =item * L<CatalystX::I18N::Role::NumberFormat>
130  
131 Methods for localising numbers.
132  
133 =item * L<CatalystX::I18N::TraitFor::Request>
134  
135 Extends L<Catalyst::Request> with useful methods to help dealing with
136 various I18N related information in HTTP requests.
137  
138 =item * L<CatalystX::I18N::TraitFor::Response>
139  
140 Adds a C<Content-Language> header to the response.
141  
142 =item * L<CatalystX::I18N::Role::GetLocale>
143  
144 Tries to determine the most appropriate locale for the current request.
145  
146 =item * L<CatalystX::I18N::Model::Maketext>
147  
148 Provides access to L<Locale::Maketext> classes via a Catalyst model.
149  
150 =item * L<CatalystX::I18N::Model::DataLocalize>
151  
152 Provides access to a L<Data::Localize> class via a Catalyst model.
153  
154 =item * L<CatalystX::I18N::Maketext>
155  
156 Helpful wrapper around L<Locale::Maketext>. Can also be used outside of
157 Catalyst.
158  
159 =item * L<CatalystX::I18N::DataLocalize>
160  
161 Helpful wrapper around L<Data::Localize>. Can also be used outside of
162 Catalyst.
163  
164 =back
165  
166 =head1 CONFIGURATION
167  
168 In order to work properly, CatalystX::I18N will need some values in your
169 Catalyst configuration
170  
171 __PACKAGE__->config(
172 name => 'MyApp',
173 I18N => {
174 default_locale => 'de_AT', # Fallback locale
175 locales => {
176 'de' => {
177 inactive => 1,
178 # Mark this locale as inactive (sort of abstract locale)
179 ...
180 # Arbitrary configuration parameters
181 },
182 'de_AT' => {
183 inherits => 'de',
184 # Inherit all settings form the 'de' locale
185 ...
186 },
187 }
188 },
189 );
190  
191 The configuration must be stored under the key C<I18N>. It should contain
192 a hashref of C<locales> and optionally a default locale (C<default_locale>).
193  
194 Locales can be marked as C<inactive>. Inactive locales will not be selected
195 by the L<CatalystX::I18N::Role::GetLocale/get_locale> method.
196  
197 Locales can inherit from other locales (C<inherits>). All configuration values
198 from inherited locales will be copied. If you use
199 L<CatalystX::I18N::Model::Maketext> together with L<CatalystX::I18N::Maketext>
200 the generated lexicons will also inherit in the selected order.
201  
202 Additional configuration values are defined by the various
203 CatalystX::I18N::Role::* plugins.
204  
205 =head1 EXTENDING
206  
207 Extending the functionality of CatalystX::I18N distribution is easy.
208  
209 E.g. writing a new plugin that does some processing when the locale is set
210  
211 package CatalystX::MyI18N::Role::MyPlugin;
212 use Moose::Role;
213 use namespace::autoclean;
214
215 after 'set_locale' => sub {
216 my ($c,$locale) = @_;
217 $c->do_someting($c->locale);
218 };
219
220 1;
221  
222 =head1 SEE ALSO
223  
224 L<Locale::Maketext>, <Locale::Maketext::Lexicon>, L<Data::Localize>,
225 L<Number::Format>, L<DateTime::Locale>, L<DateTime::Format::CLDR>,
226 L<DateTime::TimeZone>, L<HTTP::BrowserDetect> and L<Locale::Geocode>
227  
228 =head1 SUPPORT
229  
230 Please report any bugs or feature requests to
231 C<catalystx-i18n@rt.cpan.org>, or through the web interface at
232 L<http://rt.cpan.org/Public/Bug/Report.html?Queue=CatalystX::I18N>.
233 I will be notified and then you'll automatically be notified of the progress
234 on your report as I make changes.
235  
236 =head1 AUTHOR
237  
238 Maroš Kollár
239 CPAN ID: MAROS
240 maros [at] k-1.com
241
242 http://www.k-1.com
243  
244 =head1 COPYRIGHT
245  
246 CatalystX::I18N is Copyright (c) 2012 Maroš Kollár
247 - L<http://www.k-1.com>
248  
249 =head1 LICENCE
250  
251 This library is free software, you can redistribute it and/or modify
252 it under the same terms as Perl itself.
253  
254 =cut
« CatalystX/I18N/TypeConstraints.pm ↑ Summary