Catalyst::Plugin::I18N::DBI - DBI based I18N for Catalyst
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']) %]
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.
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', }, );
This is the Data Source Name which will be passed to the connect method of DBI. See DBI for more information about DSN syntax.
connect
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.)
fail_with
0
The password for the database user.
An array reference with language names that shall be loaded into memory. Basically, this is the content of the lang column.
lang
Defines the model for the lexicon table.
Boolean indicating whether to use the fail_with function or not. Defaults to true. See "FAQ" for details.
Default language which is chosen when no browser accepted language is available.
Localize text:
print $c->loc('Welcome to Catalyst, [_1]', 'Matt');
Alias method to "loc".
Contains languages.
$c->languages(['de_DE']); print join '', @{ $c->languages };
C::P::I18N::DBI
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.
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.
FooBar
? FooBar
You can disable this behavior by setting the config key fail_with to zero.
Calatyst, Locale::Maketext, Locale::Maketext::Lexicon, Locale::Maketext::Lexicon::DBI, DBI, Catalyst::Plugin::I18N::DBIC
Matthias Dietrich, <perl@rainboxx.de>, http://www.rainboxx.de
<perl@rainboxx.de>
Rafael Kitover and Octavian Râşniţă for Bugfixes
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:
Non-ASCII character seen before =encoding in 'Râşniţă'. Assuming UTF-8
To install Catalyst::Plugin::I18N::DBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::I18N::DBI
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::I18N::DBI
For more information on module installation, please visit the detailed CPAN module installation guide.