Locale::TextDomain::OO::Lexicon::Hash - Lexicon from data structure
$Id: Hash.pm 618 2015-08-22 18:02:42Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Lexicon/Hash.pm $
1.023
This module allows to create a lexicon from data structure.
require Locale::TextDomain::OO::Lexicon::Hash; Locale::TextDomain::OO::Lexicon::Hash ->new( # all parameters are optional logger => sub { my ($message, $arg_ref) = @_; my $type = $arg_ref->{type}; # debug Log::Log4perl->get_logger(...)->$type($message); return; }, ) ->lexicon_ref({ ... });
Fill in lexicon data from Perl data structure.
For language "de-de", no category (default) and no domain (default) the lexicon name is "de-de::".
For language "en", category "LC_MESSAGES" and domain "test" the lexicon name is "en:LC_MESSAGES:test".
The keys of each item are stolen from PO file. Except the keys "msgstr_plural[0]", "msgstr_plural[1]", ... "msgstr_plural[N]" are written as key "msgstr_plural" with an array reference as value.
$self->lexicon_ref({ 'de:MyCategory:MyDomain' . ':OptionalProject' => [ # header in a very minimalistic form { msgid => "", msgstr => "" . "Content-Type: text/plain; charset=UTF-8\n" . "Plural-Forms: nplurals=2; plural=n != 1;", }, # single translation { msgid => "help", msgstr => "Hilfe", }, # with context { msgctxt => "datetime", msgid => "date", msgstr => "Datum", }, # plural { msgid => "person", msgid_plural => "persons", msgstr_plural => [ "Person", "Personen", ], }, # plural with context { msgctxt => "appointment", msgid => "date", msgid_plural => "dates", msgstr_plural => [ "Date", "Dates", ], }, ], });
Set the logger
$lexicon_hash->logger( sub { my ($message, $arg_ref) = @_; my $type = $arg_ref->{type}; Log::Log4perl->get_logger(...)->$type($message); return; }, );
$arg_ref contains
object => $lexicon_hash, # the object itself type => 'debug', event => 'lexicon,load',
Inside of this distribution is a directory named example. Run this *.pl files.
confess
none
Carp
Locale::TextDomain::OO::Singleton::Lexicon
Locale::TextDomain::OO::Util::ExtractHeader
Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
Moo
MooX::StrictConstructor
namespace::autoclean
Locale::TextDomain::OO::Role::Logger
not known
Locale::TextDoamin::OO
Steffen Winkler
Copyright (c) 2013 - 2015, Steffen Winkler <steffenw at cpan.org>. All rights reserved.
<steffenw at cpan.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Locale::TextDomain::OO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::TextDomain::OO
CPAN shell
perl -MCPAN -e shell install Locale::TextDomain::OO
For more information on module installation, please visit the detailed CPAN module installation guide.