<<

NAME

Koha::Schema::Component::Localization

SYNOPSIS

    package Koha::Schema::Result::SomeTable;

    # ... generated code ...

    __PACKAGE__->load_components('+Koha::Schema::Component::Localization');

    __PACKAGE__->localization_add_relationships(
        'some_table_localizations',
        'some_table_id' => 'some_table_id',
        'first_column',
        'second_column',
        # ...
    );

    package main;

    my $rows = $schema->resultset('SomeTable');
    my $row = $rows->first;
    $row->localizations->search($cond);
    $row->create_related('first_column_localizations', { lang => $lang, translation => $translation })

    while (my $row = $rows->next)
        # first call will fetch all localizations for the current language and
        # the result will be cached, next calls will not execute a query
        $row->localization('first_column', $lang);

        # no query executed
        $row->localization('second_column', $lang);
    }

DESCRIPTION

This is a DBIx::Class component that helps to manage database localizations by adding several relationships and methods to a "Result Class"

This can handle several localizable columns (also referred as "properties") per table

To add database localizations to an existing database table, you need to:

This will give you a relationship named 'localizations' through which you can access all localizations of a particular table row.

And for every property, you will have:

The "row" object will also gain a method localization($property, $lang) which returns a specific translation and uses cache to avoid executing lots of queries

localization_add_relationships

Add relationships to the localization table

<<