The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::TraitFor::Controller::LocaleSelect - Provides locale selection mechanism for controllers

VERSION

Version 0.03

auto

This will run before your auto action, so the locale info is available even if you need it on your auto action.

SYNOPSIS

On your app class

    use Catalyst qw/
        ...    
        I18N        # or Data::Localize
        ...
    /;

    __PACKAGE__->config(
        LocaleSelect => {
            allowed => [ qw/ en es / ],
            default => 'en'
        }
    );

In your controller ( Apply to root controller to be application wide )

    package MyApp::Controller::Root;
    use Moose;
    use namespace::autoclean;

    BEGIN { extends 'Catalyst::Controller' }
    with 'Catalyst::TraitFor::Controller::LocaleSelect';
    
    # ...
    
    1;

DESCRIPTION

This controller role will provide locale selection capabilities to your controllers. You can apply it to the root controller to have it working application wide.

Once in use, the controller have auto locale selection among your configured allowed locales. When no one reported by the user agent are allowed, the default will be in use.

This role will give to all actions on the controller two more capabilities:

  • One time locale selection if exists param('locale') and have an allowed value.

  • * Cookie based locale lock-in selection using param('set_locale').

It will also populate the locale key on the stash for later extra use:

    $c->stash( locale => {
        allowed  => [ 'en', 'es' ],
        default  => 'en',
        selected => 'es'             # the one selected for the request
    });

LOCALE SELECTION PRIORITY

  1. If locale parameter exists, this will be selected.

  2. If set_locale parameter exists, it will be used an cookie stored for later use.

  3. If cookie exists...

  4. If any of the browser supported locales exists...

  5. The default one.

AUTHOR

Diego Kuperman, <diego at freekeylabs.com>

BUGS

Please report any bugs or feature requests to bug-catalyst-traitfor-controller-localeselect at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-TraitFor-Controller-LocaleSelect. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Catalyst::TraitFor::Controller::LocaleSelect

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2010 Diego Kuperman.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.