CatalystX::I18N::Role::GetLocale - Tries to determine the current users locale
package MyApp::Catalyst; use CatalystX::RoleApplicator; use Catalyst qw/MyPlugins CatalystX::I18N::Role::Base CatalystX::I18N::Role::GetLocale/; __PACKAGE__->apply_request_class_roles(qw/CatalystX::I18N::TraitFor::Request/); __PACKAGE__->setup(); package MyApp::Catalyst::Controller::Main; use strict; use warnings; use parent qw/Catalyst::Controller/; sub auto : Private { # Auto method will always be called first my ($self,$c) = @_; $c->get_locale(); }
This role provides many methods to retrieve/guess the best locale for the current user.
Tries to determine the users locale in the given order
get_locale_from_session
get_locale_from_user
get_locale_from_browser
$c->config->{I18N}{default_locale}
Sets the winning locale (via $c->locale()) if the CatalystX::I18N::Role::Base is loaded.
$c->locale()
Tries to fetch the locale from the browser (via $c->request->accept_language and $c->request->browser_language). CatalystX::I18N::TraitFor::Request must be loaded.
Tries to fetch the locale from the current session.
Tries to fetch the locale from the user object (via $c->user->locale).
Helper method to check for a valid locale
Maroš Kollár CPAN ID: MAROS maros [at] k-1.com L<http://www.k-1.com>
To install CatalystX::I18N, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::I18N
CPAN shell
perl -MCPAN -e shell install CatalystX::I18N
For more information on module installation, please visit the detailed CPAN module installation guide.