1Locale::Maketext::LexicUosne(r3)Contributed Perl DocumenLtoactailoen::Maketext::Lexicon(3)
2
3
4
6 Locale::Maketext::Lexicon - Use other catalog formats in Maketext
7
9 This document describes version 0.66 of Locale::Maketext::Lexicon,
10 released February 12, 2008.
11
13 As part of a localization class, automatically glob for available lexi‐
14 cons:
15
16 package Hello::I18N;
17 use base 'Locale::Maketext';
18 use Locale::Maketext::Lexicon {
19 '*' => [Gettext => '/usr/local/share/locale/*/LC_MESSAGES/hello.mo'],
20 ### Uncomment to decode lexicon entries into Unicode strings
21 # _decode => 1,
22 ### Uncomment to fallback when a key is missing from lexicons
23 # _auto => 1,
24 ### Uncomment to use %1 / %quant(%1) instead of [_1] / [quant, _1]
25 # _style => 'gettext',
26 };
27
28 Explicitly specify languages, during compile- or run-time:
29
30 package Hello::I18N;
31 use base 'Locale::Maketext';
32 use Locale::Maketext::Lexicon {
33 de => [Gettext => 'hello_de.po'],
34 fr => [
35 Gettext => 'hello_fr.po',
36 Gettext => 'local/hello/fr.po',
37 ],
38 };
39 # ... incrementally add new lexicons
40 Locale::Maketext::Lexicon->import({
41 de => [Gettext => 'local/hello/de.po'],
42 })
43
44 Alternatively, as part of a localization subclass:
45
46 package Hello::I18N::de;
47 use base 'Hello::I18N';
48 use Locale::Maketext::Lexicon (Gettext => \*DATA);
49 __DATA__
50 # Some sample data
51 msgid ""
52 msgstr ""
53 "Project-Id-Version: Hello 1.3.22.1\n"
54 "MIME-Version: 1.0\n"
55 "Content-Type: text/plain; charset=iso8859-1\n"
56 "Content-Transfer-Encoding: 8bit\n"
57
58 #: Hello.pm:10
59 msgid "Hello, World!"
60 msgstr "Hallo, Welt!"
61
62 #: Hello.pm:11
63 msgid "You have %quant(%1,piece) of mail."
64 msgstr "Sie haben %quant(%1,Poststueck,Poststuecken)."
65
67 This module provides lexicon-handling modules to read from other local‐
68 ization formats, such as Gettext, Msgcat, and so on.
69
70 If you are unfamiliar with the concept of lexicon modules, please con‐
71 sult Locale::Maketext and <http://www.autrijus.org/webl10n/> first.
72
73 A command-line utility xgettext.pl is also installed with this module,
74 for extracting translatable strings from source files.
75
76 The "import" function
77
78 The "import()" function accepts two forms of arguments:
79
80 (format => source ... )
81 This form takes any number of argument pairs (usually one); source
82 may be a file name, a filehandle, or an array reference.
83
84 For each such pair, it pass the contents specified by the second
85 argument to Locale::Maketext::Lexicon::format->parse as a plain
86 list, and export its return value as the %Lexicon hash in the call‐
87 ing package.
88
89 In the case that there are multiple such pairs, the lexicon defined
90 by latter ones overrides earlier ones.
91
92 { language => [ format, source ... ] ... }
93 This form accepts a hash reference. It will export a %Lexicon into
94 the subclasses specified by each language, using the process
95 described above. It is designed to alleviate the need to set up a
96 separate subclass for each localized language, and just use the
97 catalog files.
98
99 This module will convert the language arguments into lowercase, and
100 replace all "-" with "_", so "zh_TW" and "zh-tw" will both map to
101 the "zh_tw" subclass.
102
103 If language begins with "_", it is taken as an option that controls
104 how lexicons are parsed. See "Options" for a list of available
105 options.
106
107 The "*" is a special language; it must be used in conjunction with
108 a filename that also contains "*"; all matched files with a valid
109 language code in the place of "*" will be automatically prepared as
110 a lexicon subclass. If there is multiple "*" in the filename, the
111 last one is used as the language name.
112
113 Options
114
115 "_auto"
116 If set to a true value, missing lookups on lexicons are handled
117 silently, as if an "Auto" lexicon has been appended on all language
118 lexicons.
119
120 "_decode"
121 If set to a true value, source entries will be converted into
122 utf8-strings (available in Perl 5.6.1 or later). This feature
123 needs the Encode or Encode::compat module.
124
125 Currently, only the "Gettext" backend supports this option.
126
127 "_encoding"
128 This option only has effect when "_decode" is set to true. It
129 specifies an encoding to store lexicon entries, instead of
130 utf8-strings.
131
132 If "_encoding" is set to "locale", the encoding from the current
133 locale setting is used.
134
135 Subclassing format handlers
136
137 If you wish to override how sources specified in different data types
138 are handled, please use a subclass that overrides "lexicon_get_TYPE".
139
140 XXX: not documented well enough yet. Patches welcome.
141
143 When you attempt to localize an entry missing in the lexicon, Maketext
144 will throw an exception by default. To inhibit this behaviour, over‐
145 ride the "_AUTO" key in your language subclasses, for example:
146
147 $Hello::I18N::en::Lexicon{_AUTO} = 1; # autocreate missing keys
148
149 If you want to implement a new "Lexicon::*" backend module, please note
150 that "parse()" takes an array containing the source strings from the
151 specified filehandle or filename, which are not "chomp"ed. Although if
152 the source is an array reference, its elements will probably not con‐
153 tain any newline characters anyway.
154
155 The "parse()" function should return a hash reference, which will be
156 assigned to the typeglob (*Lexicon) of the language module. All it
157 amounts to is that if the returned reference points to a tied hash, the
158 %Lexicon will be aliased to the same tied hash if it was not initial‐
159 ized previously.
160
162 Thanks to Jesse Vincent for suggesting this module to be written.
163
164 Thanks also to Sean M. Burke for coming up with Locale::Maketext in the
165 first place, and encouraging me to experiment with alternative Lexicon
166 syntaxes.
167
168 Thanks also to Yi Ma Mao for providing the MO file parsing subroutine,
169 as well as inspiring me to implement file globbing and transcoding sup‐
170 port.
171
172 See the AUTHORS file in the distribution for a list of people who have
173 sent helpful patches, ideas or comments.
174
176 xgettext.pl for extracting translatable strings from common template
177 systems and perl source files.
178
179 Locale::Maketext, Locale::Maketext::Lexicon::Auto, Locale::Make‐
180 text::Lexicon::Gettext, Locale::Maketext::Lexicon::Msgcat,
181 Locale::Maketext::Lexicon::Tie
182
184 Audrey Tang <cpan@audreyt.org>
185
187 Copyright 2002-2008 by Audrey Tang <cpan@audreyt.org>.
188
189 This software is released under the MIT license cited below.
190
191 The "MIT" License
192
193 Permission is hereby granted, free of charge, to any person obtaining a
194 copy of this software and associated documentation files (the "Soft‐
195 ware"), to deal in the Software without restriction, including without
196 limitation the rights to use, copy, modify, merge, publish, distribute,
197 sublicense, and/or sell copies of the Software, and to permit persons
198 to whom the Software is furnished to do so, subject to the following
199 conditions:
200
201 The above copyright notice and this permission notice shall be included
202 in all copies or substantial portions of the Software.
203
204 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
205 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MER‐
206 CHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
207 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
208 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
209 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT‐
210 WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
211
212
213
214perl v5.8.8 2008-01-07 Locale::Maketext::Lexicon(3)