Locale::Maketext::Lexicon::DBI - Database based lexicon fetcher/parser
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 ] ], };
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.
DBI
[_1]
[_2]
[_*]
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!
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::DBI to select the right lexicon entries.
Locale::Maketext::Lexicon::DBI
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.
Locale::Maketext::Lexicon::DBI don't want to connect to the database each time it should fetch the content. This parameter contains the database handle created by DBI.
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, lex_key text, lex_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, lex_key and lex_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.
lang
lex
lex_key
lex_value
notes
IMPORTANT! Read this if you are updating from a version prior to v0.2.0!
Version 0.2.0 fixes an issue when not using PostgreSQL as RDBMS, since key and value may be reserved words. You need to alter the table lexicon as described above in "DB TABLE DEFINITION": change key to lex_key and value to lex_value.
key
value
lexicon
Locale::Maketext, Locale::Maketext::Lexicon, DBI
Matthias Dietrich, <perl@rainboxx.de>, http://www.rainboxx.de
<perl@rainboxx.de>
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 Locale::Maketext::Lexicon::DBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Maketext::Lexicon::DBI
CPAN shell
perl -MCPAN -e shell install Locale::Maketext::Lexicon::DBI
For more information on module installation, please visit the detailed CPAN module installation guide.