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

NAME

Catalyst::Plugin::I18N::DBI - DBI based I18N for Catalyst

SYNOPSIS

    use Catalyst 'I18N::DBI';

    print $c->loc('Hello Catalyst');

Or in your Mason code:

   <% $c->loc('Hello [_1]', 'Catalyst') %>

Or in your TT code (with macro):

   [% MACRO l(text, args) BLOCK;
       c.loc(text, args);
   END; %]

   [% l('Hello Catalyst') %]
   [% l('Hello [_1]', 'Catalyst') %]
   [% l('lalala[_1]lalala[_2]', ['test', 'foo']) %]

DESCRIPTION

Unlike Catalyst::Plugin::I18N::DBIC this plugin isn't based on any other Catalyst plugin. It makes direct use of Locale::Maketext::Lexicon and Locale::Maketext::Lexicon::DBI.

Lexicon texts are held in a database table where you can have several lexicons which are separated by the 'lex' column. See Locale::Maketext::Lexicon::DBI for more information about the table definition. All specified lexicons are loaded into memory at startup, so we don't need to fetch the lexicon entries every time we need them.

Please read this document and Catalyst::Plugin::I18N::DBIC's POD carefully before deciding which module to use in your case.

CONFIGURATION

In order to be able to connect to the database, this plugin needs some configuration, for example:

    __PACKAGE__->config(
        'I18N::DBI' => {
                         dsn          => 'dbi:Pg:dbname=postgres',
                         user         => 'pgsql',
                         password     => '',
                         languages    => [qw(de en)],
                         lexicons     => [qw(*)],
                         lex_class    => 'DB::Lexicon',
                         default_lang => 'de',
                       },
    );
dsn

This is the Data Source Name which will be passed to the connect method of DBI. See DBI for more information about DSN syntax.

user

Name of a database user with read and write access to the lexicon table and dependent sequences. (When fail_with is set to 0, the user doesn't need to have write access.)

password

The password for the database user.

languages

An array reference with language names that shall be loaded into memory. Basically, this is the content of the lang column.

lex_class

Defines the model for the lexicon table.

fail_with

Boolean indicating whether to use the fail_with function or not. Defaults to true. See "FAQ" for details.

default_lang

Default language which is chosen when no browser accepted language is available.

METHODS

loc

Localize text:

    print $c->loc('Welcome to Catalyst, [_1]', 'Matt');

localize

Alias method to "loc".

languages

Contains languages.

   $c->languages(['de_DE']);
   print join '', @{ $c->languages };

EXTENDED AND INTERNAL METHODS

setup

FAQ

Why use C::P::I18N::DBI instead of C::P::I18N::DBIC?

Sometimes you don't want to select and parse the data from the database each time you access your lexicon. Then C::P::I18N::DBI is for you! It loads the lexicon into memory at startup instead of fetching it over and over again. But be careful, as this approach can waste a lot of memory and may slow your system down (depending of the amount of data in your lexicon).

I recommend to test both modules and decide which one is more suitable depending on your production environment.

Why does the database user needs write access? Or: What's the fail_with function?

C::P::I18N::DBI implements a fail_with method that attempts to create a new database entry whenever a lexicon lookup fails. The value is set to the lexicon key prefixed with the string ? .

Example: you look up FooBar, which doesn't exist. A new database entry will be created with that key, the value will be ? FooBar.

You can disable this behavior by setting the config key fail_with to zero.

SEE ALSO

Calatyst, Locale::Maketext, Locale::Maketext::Lexicon, Locale::Maketext::Lexicon::DBI, DBI, Catalyst::Plugin::I18N::DBIC

AUTHOR

Matthias Dietrich, <perl@rainboxx.de>, http://www.rainboxx.de

THANKS TO

Rafael Kitover and Octavian Râşniţă for Bugfixes

COPYRIGHT AND LICENSE

Copyright 2008 - 2009 rainboxx Matthias Dietrich. All Rights Reserved.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 301:

Non-ASCII character seen before =encoding in 'Râşniţă'. Assuming UTF-8