Maroš Kollár > CatalystX-I18N > CatalystX::I18N::Role::GetLocale

Download:
CatalystX-I18N-1.13.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

CatalystX::I18N::Role::GetLocale - Tries to determine the current users locale

SYNOPSIS ^

 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();
 }

DESCRIPTION ^

This role provides many methods to retrieve/guess the best locale for the current user.

METHODS ^

get_locale

Tries to determine the users locale in the given order

1. Session (via get_locale_from_session)
2. User (via get_locale_from_user)
3. Browser (via get_locale_from_browser)
4. Default locale from config (via $c->config->{I18N}{default_locale})
5. Random locale

Sets the winning locale (via $c->locale()) if the CatalystX::I18N::Role::Base is loaded.

get_locale_from_browser

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.

get_locale_from_session

Tries to fetch the locale from the current session.

get_locale_from_user

Tries to fetch the locale from the user object (via $c->user->locale).

check_locale

Helper method to check for a valid locale

AUTHOR ^

    Maroš Kollár
    CPAN ID: MAROS
    maros [at] k-1.com
    
    L<http://www.k-1.com>
syntax highlighting: