NAME

Multilingual - special component class, which supports several languages


SYNOPSIS

        # You should subclass your real multi-lingual component class
        package Podius::Component::MyMultilingual;
        @ISA = qw(Podius::Component::Multilingual);
        sub get_own_property_types ($) {
                return [
                        [ is_enabled => MultilingualSelection, {
                                0 => { 0 => 'No', 1 => 'Yes' },
                                1 => { 0 => 'lo', 1 => 'ken' },
                        } ],
                        [ title => 'Scalar' ],
                ];
        }
        sub get_own_language_agnostic_property_names ($) {
                return [ 'is_enabled' ];
        }
        package main;
        use Podius;
        use Podius::Component::MyMultilingual;
        my $mlc = new Podius::Component::MyMultilingual;
        $mlc->language(1);  # or ->language_label('Hebrew')
        $mlc->is_enabled(1);
        $mlc->is_enabled_code(1);            # the same thing
        $mlc->is_enabled_label('ken');       # the same thing
        print $mlc->is_enabled, "\n";        # prints 1
        print $mlc->is_enabled_code, "\n";   # the same thing
        print $mlc->is_enabled_label, "\n";  # prints 'ken'


DESCRIPTION

This package implements superclass of components, supporting several languages in their properties. It supposes there are language-clone component collection of the one logical component. It sets active language for multi-lingual properties and synchronizes language-agnostic properties in language-clones of this component.


REQUIREMENTS

the Exception manpage, the Podius::Component::Publishable manpage, the Podius::Property::MultilingualLanguage manpage, the Podius::Property::VComponentCollection manpage.


METHODS

sync_language_clones

description
Syncronizes all components in language_clones virtual collection with this component. This include (for each language-cloned component):
        * language_clones collection is set according to this component
        * all language-agnostic properties are updated from this component

returns
1 on success. On failure exception is thrown.

get_language_clone_by_language

description
Queries this component and its language_clones to find a clone in the specified language. If no such language clone is found, the exception is thrown.

Note, no consistency of the collection is checked, the first matching component is returned. If you need all components in the specified language, use something like this instead:

  my $french_clones = $component->language_clones
    ->filter(sub { $_[0]->language eq 'fr' })->get_all;

parameters
Language code, like ``en''.

returns
Multilingual Component having the specified language (either this component or its clone).

get_language_agnostic_property_names

description
Provides an information about component property names and their order, which are language agnostic, which means have the same values in all language-clones of this component and must be synchronized. You probably don't need to touch this method in subclasses, overwrite get_own_language_agnostic_property_names instead.

returns
Array of form [ property_name* ].

get_own_language_agnostic_property_names

description
Provides an information about own component property names (additional, non included in superclasses) and their order, which are language agnostic, which means the same in all language-clones of this component and must be synchronized. This is protected virtual method, must be owerwritten in subclasses.

returns
Array of form [ property_name* ].