Catalyst::Model::Data::Localize - Catalyst Model Over Data::Localize
$c->model('Data::Localize') # or Localize. whatever ->localize($key, @args);
WARNING: Data::Localize, which this module is based on, is still in alpha quality. This module should also be treated as such.
This is a thin wrapper around Data::Localize. The only thing it does that a plain Catalyst::Model::Adaptor + Data::Localize can do is the automatic discovery of I18N files (if they are placed under likely locations).
For example, these files will automatically be found:
# suppose our Catalyst app is at lib/MyApp.pm lib/MyApp/I18N/ja.pm lib/MyApp/I18N/ja.po
Also, for those like me that don't like to put a catalyst app at the project's top namespace, we look for one level above, too:
# suppose our Catalyst app is at lib/MyApp/Web.pm lib/MyApp/I18N/ja.pm lib/MyApp/I18N/ja.po
The default behavior is to detect the language setting from the HTTP headers. If you want to override it, simply place an explicit call somehwere in your action chain:
my $loc = $c->model('Data::Localize'); $loc->set_languages('ja'); # or whatever you prefer $loc->localize($key, @args);
Configuration can be done via the 'Model::Data::Localize' slot:
<Model::Data::Localize> auto 1 <localizers> class Gettext path /path/to/gettext/files/*.po </localizers> </Model::Data::Localize>
If you want Catalyst::Plugin::I18N compatible style method generation on the context object, look at Catalyst::Plugin::Data::Localize, which is just a really thin wrapper over this module.
languages parameter is a bit special, as it overrides the default behavior to detect the desired language from HTTP headers.
languages
# Always use ja <Model::Data::Localize> languages ja </Model::Data::Localize>
Tests. Yes, I know.
Daisuke Maki <daisuke@endeworks.jp>
<daisuke@endeworks.jp>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Catalyst::Model::Data::Localize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::Data::Localize
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::Data::Localize
For more information on module installation, please visit the detailed CPAN module installation guide.