1Locale::TextDomain::OO:U:sLeerxiCcoonnt:r:iHbausthe(d3L)PoecralleD:o:cTuemxetnDtoamtaiionn::OO::Lexicon::Hash(3)
2
3
4

NAME

6       Locale::TextDomain::OO::Lexicon::Hash - Lexicon from data structure
7
8       $Id: Hash.pm 698 2017-09-28 05:21:05Z steffenw $
9
10       $HeadURL:
11       svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Lexicon/Hash.pm
12       $
13

VERSION

15       1.031
16

DESCRIPTION

18       This module allows to create a lexicon from data structure.
19

SYNOPSIS

21           require Locale::TextDomain::OO::Lexicon::Hash;
22           use Log::Any qw($log);
23
24           $logger = Locale::TextDomain::OO::Lexicon::Hash
25               ->new(
26                   # all parameters are optional
27                   logger => sub {
28                       my ($message, $arg_ref) = @_;
29                       my $type = $arg_ref->{type}; # debug
30                       $log->$type($message);
31                       return;
32                   },
33               )
34               ->lexicon_ref({ ... })
35               ->logger;
36

SUBROUTINES/METHODS

38   method new
39       see SYNOPSIS
40
41   method lexicon_ref
42       Fill in lexicon data from Perl data structure.
43
44       For language "de-de", no category (default) and no domain (default) the
45       lexicon name is "de-de::".
46
47       For language "en", category "LC_MESSAGES" and domain "test" the lexicon
48       name is "en:LC_MESSAGES:test".
49
50       The keys of each item are stolen from PO file.  Except the keys
51       "msgstr_plural[0]", "msgstr_plural[1]", ... "msgstr_plural[N]" are
52       written as key "msgstr_plural" with an array reference as value.
53
54           $self->lexicon_ref({
55               'de:MyCategory:MyDomain' . ':OptionalProject' => [
56                   # header in a very minimalistic form
57                   {
58                       msgid  => "",
59                       msgstr => ""
60                           . "Content-Type: text/plain; charset=UTF-8\n"
61                           . "Plural-Forms: nplurals=2; plural=n != 1;",
62                   },
63                   # single translation
64                   {
65                       msgid  => "help",
66                       msgstr => "Hilfe",
67                   },
68                   # with context
69                   {
70                       msgctxt => "datetime",
71                       msgid   => "date",
72                       msgstr  => "Datum",
73                   },
74                   # plural
75                   {
76                       msgid         => "person",
77                       msgid_plural  => "persons",
78                       msgstr_plural => [
79                           "Person",
80                           "Personen",
81                       ],
82                   },
83                   # plural with context
84                   {
85                       msgctxt       => "appointment",
86                       msgid         => "date",
87                       msgid_plural  => "dates",
88                       msgstr_plural => [
89                           "Date",
90                           "Dates",
91                       ],
92                   },
93               ],
94           });
95
96   method logger
97       Set the logger and get back them
98
99           $lexicon_hash->logger(
100               sub {
101                   my ($message, $arg_ref) = @_;
102                   my $type = $arg_ref->{type};
103                   $log->$type($message);
104                   return;
105               },
106           );
107           $logger = $lexicon_hash->logger;
108
109       $arg_ref contains
110
111           object => $lexicon_hash, # the object itself
112           type   => 'debug',
113           event  => 'lexicon,load', # The logger will be copied to
114                                     # Locale::TextDomain::OO::Singleton::Lexicon
115                                     # so more events are possible.
116

EXAMPLE

118       Inside of this distribution is a directory named example.  Run this
119       *.pl files.
120

DIAGNOSTICS

122       confess
123

CONFIGURATION AND ENVIRONMENT

125       none
126

DEPENDENCIES

128       Carp
129
130       Locale::TextDomain::OO::Singleton::Lexicon
131
132       Locale::TextDomain::OO::Util::ExtractHeader
133
134       Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
135
136       Moo
137
138       MooX::StrictConstructor
139
140       namespace::autoclean
141
142       Locale::TextDomain::OO::Role::Logger
143

INCOMPATIBILITIES

145       not known
146

BUGS AND LIMITATIONS

148       none
149

SEE ALSO

151       Locale::TextDoamin::OO
152

AUTHOR

154       Steffen Winkler
155
157       Copyright (c) 2013 - 2017, Steffen Winkler "<steffenw at cpan.org>".
158       All rights reserved.
159
160       This module is free software; you can redistribute it and/or modify it
161       under the same terms as Perl itself.
162
163
164
165perl v5.28.0                      2017-L0o9c-a2l8e::TextDomain::OO::Lexicon::Hash(3)
Impressum