Skip to content

trwww/CatalystX-I18N

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Optionally also load request and response roles

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', }, } }, );

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 necessarry.

Basic I18N role that glues everything toghether.

Adds a maketext capability to a Catalyst application.

Methods for localizing date and time informations.

Methods for localizing numbers.

Extends a Catalyst::Request with usefull methods to help dealing with various I18N related information in HTTP requests.

Adds a Content-Language header to the response.

Tries best to determine the request locale.

Provides access to Locale::Maketext classes via Catalyst models.

Wrapper arround Locale::Maketext. Can also be used outside of Catalyst.

CONFIGURATION

In order to work properly, CatalystX::I18N will need find some values in your Catalyst configuration

PACKAGE->config( name => 'MyApp', I18N => { default_locale => 'de_AT', locales => { 'de' => { inactive => 1, # Mark this locale as inactive. ... # Arbitrary configuration parameters }, 'de_AT' => { inherits => 'de', # Inherit all settings form locale 'de' ... }, } }, );

The configuration must be stored under the key I18N. It should contain a hash of locales and optionally a default locale (default_locale).

Locales can be marked as inactive. Inactive locales will not be selected by the LCatalystX::I18N::Role::GetLocale/get_locale method.

Locales can inherit from other locales (inherits). All configuration values from inherited locales will be copied, and add if you use CatalystX::I18N::Model::L10N together with CatalystX::I18N::L10N the generated lexicons will also inherit in the given order.

Additional configuration values are defined by the various CatalystX::I18N::Role::Maketext::* plugins.

EXTENDING

Extending the functionality of the CatalystX::I18N distribution is easy.

E.g. writing a new plugin that does some processing when the locale changes

package CatalystX::MyI18N::Plugin; use Moose::Role;

after 'set_locale' => sub { my ($c,$locale) = @_; $c->do_someting($locale); };

no Moose::Role; 1;

SEE ALSO

Locale::Maketext, Locale::Maketext::Lexicon, Number::Format, DateTime::Locale, DateTime::Format::CLDR, DateTime::TimeZone, HTTP::BrowserDetect and Locale::Geocode

SUPPORT

Please report any bugs or feature requests to catalystx-i18n@rt.cpan.org, 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


L<http://www.revdev.at>

COPYRIGHT

CatalystX::I18N is Copyright (c) 2010 Maroš Kollár

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

About

I18N Toolkit for the Catalyst MVC

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Perl 100.0%