man Locale::Maketext::Lexicon () - Use other catalog formats in Maketext
NAME
Locale::Maketext::Lexicon - Use other catalog formats in Maketext
VERSION
This document describes version 0.53 of Locale::Maketext::Lexicon, released December 5, 2005.
SYNOPSIS
As part of a localization class, automatically glob for available lexicons:
package Hello::I18N; use base 'Locale::Maketext'; use Locale::Maketext::Lexicon { '*' => [Gettext => '/usr/local/share/locale/*/LC_MESSAGES/hello.mo'], _decode => 1, # decode lexicon entries into utf8-strings };
Explicitly specify languages, during compile- or run-time:
package Hello::I18N; use base 'Locale::Maketext'; use Locale::Maketext::Lexicon { de => [Gettext => 'hello_de.po'], fr => [ Gettext => 'hello_fr.po', Gettext => 'local/hello/fr.po', ], }; # ... incrementally add new lexicons Locale::Maketext::Lexicon->import({ de => [Gettext => 'local/hello/de.po'], })
Alternatively, as part of a localization subclass:
package Hello::I18N::de; use base 'Hello::I18N'; use Locale::Maketext::Lexicon (Gettext => \*DATA); __DATA__ # Some sample data msgid "" msgstr "" "Project-Id-Version: Hello 1.3.22.1\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso8859-1\n" "Content-Transfer-Encoding: 8bit\n"
#: Hello.pm:10 msgid "Hello, World!" msgstr "Hallo, Welt!"
#: Hello.pm:11 msgid "You have %quant(%1,piece) of mail." msgstr "Sie haben %quant(%1,Poststueck,Poststuecken)."
DESCRIPTION
This module provides lexicon-handling modules to read from other localization formats, such as Gettext, Msgcat, and so on.
If you are unfamiliar with the concept of lexicon modules, please consult Locale::Maketext and <http://www.autrijus.org/webl10n/> first.
A command-line utility xgettext.pl is also installed with this module, for extracting translatable strings from source files. The CWimport() function accepts two forms of arguments:
- (format => source ... )
- This form takes any number of argument pairs (usually one); source may be a file name, a filehandle, or an array reference. For each such pair, it pass the contents specified by the second argument to Locale::Maketext::Lexicon::BIformat->parse as a plain list, and export its return value as the CW%Lexicon hash in the calling package. In the case that there are multiple such pairs, the lexicon defined by latter ones overrides earlier ones.
- { language => [ format, source ... ] ... }
- This form accepts a hash reference. It will export a CW%Lexicon into the subclasses specified by each language, using the process described above. It is designed to alleviate the need to set up a separate subclass for each localized language, and just use the catalog files. This module will convert the language arguments into lowercase, and replace all CW- with CW_, so CWzh_TW and CWzh-tw will both map to the CWzh_tw subclass. If language begins with CW_, it is taken as an option that controls how lexicons are parsed. See Options for a list of available options. The CW* is a special language; it must be used in conjunction with a filename that also contains CW*; all matched files with a valid language code in the place of CW* will be automatically prepared as a lexicon subclass. If there is multiple CW* in the filename, the last one is used as the language name.
Options
If set to a true value, source entries will be converted into utf8-strings (available in Perl 5.6.1 or later). This feature needs the Encode or Encode::compat module. Currently, only the CWGettext backend supports this option. This option only has effect when CW_decode is set to true. It specifies an encoding to store lexicon entries, instead of utf8-strings. If CW_encoding is set to CWlocale, the encoding from the current locale setting is used.
Subclassing format handlers
If you wish to override how sources specified in different data types are handled, please use a subclass that overrides CWlexicon_get_CITYPECW. XXX: not documented well enough yet. Patches welcome.
NOTES
When you attempt to localize an entry missing in the lexicon, Maketext will throw an exception by default. To inhibit this behaviour, override the CW_AUTO key in your language subclasses, for example:
$Hello::I18N::en::Lexicon{_AUTO} = 1; # autocreate missing keysIf you want to implement a new CWLexicon::* backend module, please note that CWparse() takes an array containing the source strings from the specified filehandle or filename, which are not CWchomped. Although if the source is an array reference, its elements will probably not contain any newline characters anyway. The CWparse() function should return a hash reference, which will be assigned to the typeglob (CW*Lexicon) of the language module. All it amounts to is that if the returned reference points to a tied hash, the CW%Lexicon will be aliased to the same tied hash if it was not initialized previously.
ACKNOWLEDGMENTS
Thanks to Jesse Vincent for suggesting this module to be written. Thanks also to Sean M. Burke for coming up with Locale::Maketext in the first place, and encouraging me to experiment with alternative Lexicon syntaxes. Thanks also to Yi Ma Mao for providing the MO file parsing subroutine, as well as inspiring me to implement file globbing and transcoding support. See the AUTHORS file in the distribution for a list of people who have sent helpful patches, ideas or comments.
SEE ALSO
xgettext.pl for extracting translatable strings from common template systems and perl source files. Locale::Maketext, Locale::Maketext::Lexicon::Auto, Locale::Maketext::Lexicon::Gettext, Locale::Maketext::Lexicon::Msgcat, Locale::Maketext::Lexicon::Tie
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
Copyright 2002, 2003, 2004, 2005 by Autrijus Tang <autrijus@autrijus.org>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html>