CatalystX::I18N::Role::Collate - Support for localised collation
package MyApp::Catalyst; use Catalyst qw/MyPlugins CatalystX::I18N::Role::Base CatalystX::I18N::Role::Collate/; package MyApp::Catalyst::Controller::Main; use strict; use warnings; use parent qw/Catalyst::Controller/; sub action : Local { my ($self,$c) = @_; $c->locale('de'); @sorted_names = $c->i18n_sort(qw/Algerien Ägypten Armenien Argentinien Äthiopien Afganistan Aserbaidschan/); $c->stash->{names} = \@sorted_names; }
This role adds support for localised collation your Catalyst application.
my @german_alphabeth = (A..Z,a..z,'ä','Ä','ü','Ü','ö','Ö','ß'); $sort = join(',',sort @german_alphabeth); # $sort_no_collate is 'A,B,C,[...],Z,a,b,c,[...],z,Ä,Ö,Ü,ß,ä,ö,ü' $sort_localised = join(',',$c->i18n_sort(@german_alphabeth)); # $sort_no_collate is 'a,A,ä,Ä,b,B,c,C,[...],s,S,ß,t,T,u,U,ü,Ü,v,V,w,[...],z,Z'
All methods are lazy. This means that the values will be only calculated upon the first call of the method.
my @sorted = $c->i18n_sort(@list); OR my $sorted = $c->i18n_sort(\@list);
Sorts the given list or arrayref with the current locale and returns a list or arrayref.
my $collator = $c->i18n_collator();
Returns a Unicode::Collate::Locale object with the current language used as the locale. The collator settings can be configured in your Catalyst I18N configuration:
# Add some I18N configuration __PACKAGE__->config( name => 'MyApp', I18N => { default_locale => 'de_AT', locales => { 'de_AT' => { collate => { level => 3, variable => 'Non-Ignorable', ... }, }, } }, );
The following configuration options are available (see Unicode::Collate for detailed documentation):
UCA_Version
alternate
backwards
entry
hangul_terminator
ignoreChar
katakana_before_hiragana
level
normalization
overrideCJK
overrideHangul
preprocess
rearrange
suppress
table
undefName
undefChar
upper_before_lower
variable
Unicode::Collate
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.