DBIx::Class::I18NColumns - Internationalization for DBIx::Class Result class
Version 0.15
package MySchema::Result::Song; use strict; use warnings; use parent 'DBIx::Class'; __PACKAGE__->load_components( qw/ I18NColumns Core / ); __PACKAGE__->table( 'song' ); __PACKAGE__->add_columns( 'id', { data_type => 'INT', default_value => 0, is_nullable => 0 }, 'author', { data_type => 'VARCHAR', default_value => "", is_nullable => 0, size => 255 }, ); __PACKAGE__->add_i18n_columns( 'title', { data_type => 'VARCHAR', default_value => "", is_nullable => 0, size => 255 }, 'lyrics', { data_type => 'TEXT', default_value => "", is_nullable => 0 }, ); __PACKAGE__->set_primary_key( 'id' ); 1; # then, you have an auto generated resultset where title and lyrics are stored # in different languages: my $song = $myschema->resultset( 'Song' )->create({ author => 'Flopa', title => 'Germinar', lyrics => 'La vida se toma como el vino pura, y ...', language => 'es', }); print $song->title; # prints 'Germinar' $song->language('en'); $song->title('To germinate'); # set title in english $song->lyrics('traslated lyrics'); # set lyrics in english $song->update; # store title and lyrics print $song->title; # prints 'To Germinate' print $song->title(['es']); # prints 'Germinar' $song->language('es'); print $song->title; # prints 'Germinar'
This module allows you to define columns that will store multiple values asociated to a language string and use it as normal columns. This is useful when you need to internationalize attributes of your DB entities.
This component will create a new resultset on your schema for each one that use it. The auto-created resultset will use the columns definition you give to add_i18n_columns() plus a FK and language columns. The i18n values of each language will reside in a row of this resultset and will transparently work as any other column as long as you provide a language to your row or resultset methods as you can see at the synopsis.
Language will be propagated to relationships with result sources that also use this component.
Create internationalizable columns. The columns are created in the same way you do with in add_columns.
If you don't specify the data_type, varchar will be used by default.
Get or set the language for the row.
Retuns an instance of the resultset where i18n strings are stored.
By default, this component will set the resultset class to DBIx::Class::ResultSet::I18NColumns. If you need to write your own resultset methods, you'll need to overwrite this method to return false and then, you write your resultset class as usual but based on DBIx::Class::ResultSet::I18NColumns instead of DBIx::Class::ResultSet.
In your result class that use this component:
sub auto_resultset_class { 0 }
Then, in your resultset class you should do something like:
package MySchema::ResultSet::Item; use base 'DBIx::Class::ResultSet::I18NColumns'; # ... your rs methods ... 1;
as described on the manual.
By default, this component will autocreate the result class that will be used to store internationalized values. You can overwrite this method to stop this component doing this and then you must create it manually.
sub auto_i18n_rs { 0 }
A has_many relationship to the i18n resultset will be added to your RS if auto_i18n_rs is allowed.
Returns an array of available languages.
Check for a given language to be present on the row.
The name for the language column to be used and autocreated. Defaults on 'language'.
The name for the column to store the PK of the internationalized result class. Defaults on id_[table name of result source]
Returns true if the source has a i18n or regular column of this name, false otherwise.
Returns true if the source has a i18n column of this name, false otherwise.
Returns the name of the schema class.
Overloaded "set_column" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "store_column" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "get_column" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "update" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "insert" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "get_from_storage" in DBIx::Class::Row to manage i18n columns cleanly.
Overloaded "related_resultset" in DBIx::Class::Relationship::Base to propagate language to related resultsets that also use this component.
Make it possible to search by i18n_columns
Do not depend on the PK for the table to be on column 'id'
Make it possible to use this component on tables with multi-columns PK
This is an early release, so probable there are plenty of bugs around.
Please report any bugs or feature requests to bug-dbix-class-i18ncolumns at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-I18NColumns. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dbix-class-i18ncolumns at rt.cpan.org
Diego Kuperman, <diego at freekeylabs.com >
<diego at freekeylabs.com >
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::I18NColumns
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-I18NColumns
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/DBIx-Class-I18NColumns
CPAN Ratings
http://cpanratings.perl.org/d/DBIx-Class-I18NColumns
Search CPAN
http://search.cpan.org/dist/DBIx-Class-I18NColumns/
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.
To install DBIx::Class::I18NColumns, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::I18NColumns
CPAN shell
perl -MCPAN -e shell install DBIx::Class::I18NColumns
For more information on module installation, please visit the detailed CPAN module installation guide.