NAME
Locale::Maketext::Lexicon::DBI - Database based lexicon fetcher/parser
SYNOPSIS
Called via Locale::Maketext::Lexicon:
package Hello::I18N;
use base 'Locale::Maketext';
use DBI;
my $dbh = DBI->connect($dsn, $user, $password, $attr);
use Locale::Maketext::Lexicon {
de => [ DBI => [ lang => 'de', lex => 'lex', dbh => $dbh ] ],
};
DESCRIPTION
This module implements a perl-based DBI fetcher/"parser" for Locale::Maketext. It reads the lexicon from the database and transforms nothing but expect the placeholders to be [_1], [_2], [_*], and so on, like Locale::Maketext wants them to be.
PARAMETERS FOR Locale::Maketext::Lexicon
Usually we define source PO or MO file(s), as we do in Locale::Maketext::Lexicon::Gettext. Here we don't have files but need some parameters to access and read the database.
All three parameters are essential!
- lang
-
Although we already defined the language as the key of the hash Locale::Maketext::Lexicon imports, the language needs to be defined once again for
Locale::Maketext::Lexicon::DBIto select the right lexicon entries. - lex
-
This is an identifier (string) in the database so that the lexicon can be separated into more lexicons (e.g. for different applications/areas) within one table.
- dbh
-
Locale::Maketext::Lexicon::DBIdon't want to connect to the database each time it should fetch the content. This parameter contains the database handle created by DBI.
DB TABLE DEFINITION
This is a example table definition for PostgreSQL:
CREATE TABLE lexicon (
id serial NOT NULL,
lang character varying(15) DEFAULT NULL::character varying,
lex character varying(255) DEFAULT NULL::character varying,
"key" text,
"value" text,
notes text,
CONSTRAINT lexicon_pkey PRIMARY KEY (id)
) WITH (OIDS=FALSE);
You should easily adapt this to MySQL and other database systems. Note that the columns lang, lex, key and value are essential! Every other column can be defined by the user. notes is an optional column that can be a hint for the translator.
SEE ALSO
Locale::Maketext, Locale::Maketext::Lexicon, DBI
AUTHOR
Matthias Dietrich, <perl@rainboxx.de>
COPYRIGHT & LICENSE
Copyright 2008 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.