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