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

NAME

DBIx::Class::I18NColumns - Internationalization for DBIx::Class Result class

VERSION

Version 0.15

SYNOPSIS

    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'

DESCRIPTION

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.

METHODS

add_i18n_columns

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.

language

Get or set the language for the row.

i18n_resultset

Retuns an instance of the resultset where i18n strings are stored.

auto_resultset_class

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.

auto_i18n_rs

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.

In your result class that use this component:

    sub auto_i18n_rs { 0 }

i18n_rows

A has_many relationship to the i18n resultset will be added to your RS if auto_i18n_rs is allowed.

languages

Returns an array of available languages.

has_language

Check for a given language to be present on the row.

language_column

The name for the language column to be used and autocreated. Defaults on 'language'.

foreign_column

The name for the column to store the PK of the internationalized result class. Defaults on id_[table name of result source]

has_any_column

Returns true if the source has a i18n or regular column of this name, false otherwise.

has_i18n_column

Returns true if the source has a i18n column of this name, false otherwise.

schema_class

Returns the name of the schema class.

OVERLOADED METHODS

set_column

Overloaded "set_column" in DBIx::Class::Row to manage i18n columns cleanly.

store_column

Overloaded "store_column" in DBIx::Class::Row to manage i18n columns cleanly.

get_column

Overloaded "get_column" in DBIx::Class::Row to manage i18n columns cleanly.

update

Overloaded "update" in DBIx::Class::Row to manage i18n columns cleanly.

insert

Overloaded "insert" in DBIx::Class::Row to manage i18n columns cleanly.

get_from_storage

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.

TODO

  • 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

BUGS

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.

AUTHOR

Diego Kuperman, <diego at freekeylabs.com >

SUPPORT

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

    perldoc DBIx::Class::I18NColumns

You can also look for information at:

ACKNOWLEDGEMENTS

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.