Matthias Dietrich

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::DBI to 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::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.

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,
      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.

INCOMPATIBILITY CHANGE IN v0.2.0

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.

SEE ALSO

Locale::Maketext, Locale::Maketext::Lexicon, DBI

AUTHOR

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

THANKS TO

Octavian Râşniţă for Bugfixes

COPYRIGHT & 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 118:

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