1
package Locale::Maketext::Lexicon::Msgcat;
2
$Locale::Maketext::Lexicon::Msgcat::VERSION = '0.02';
8
Locale::Maketext::Lexicon::Msgcat - Msgcat catalog parser Maketext
13
use base 'Locale::Maketext';
14
use Locale::Maketext::Lexicon {
15
en => ['Msgcat', 'en_US/hello.pl.m'],
19
my $lh = Hello::I18N->get_handle('en');
20
print $lh->maketext(1,2); # set 1, msg 2
21
print $lh->maketext("1,2"); # same thing
25
This module parses one or more Msgcat catalogs in plain text format,
26
and returns a Lexicon hash, which may be looked up either with a
27
two-argument form (C<$set_id, $msg_id>) or as a single string
28
(C<"$set_id,$msg_id">).
32
All special characters (C<[>, C<]> and C<~>) in catalogs will be
33
escaped so they lose their magic meanings. That means C<-E<gt>maketext>
34
calls to this lexicon will I<not> take any additional arguments.
41
my ($qr, $qq, $qc) = (qr//, '', '');
44
# Set up the msgcat handler
46
*{Locale::Maketext::msgcat} = \&_msgcat; }
48
# Parse *.m files; Locale::Msgcat objects and *.cat are not yet supported.
50
s/[\015\012]*\z//; # fix CRLF issues
52
/^\$set (\d+)/ ? do { # set_id
54
push @out, $1, "[msgcat,$1,_1]";
57
/^\$quote (.)/ ? do { # quote character
63
/^(\d+) ($qr)(.*?)\2(\\?)$/ ? do { # msg_id and msg_str
65
push @out, "$set,".int($1);
70
push @out, unescape($qq, $qc, $3);
75
(defined $msg and /^($qr)(.*?)\1(\\?)$/) ? do { # continued string
81
push @out, unescape($qq, $qc, $msg . $2);
87
push @out, '' if defined $msg;
93
my ($self, $set_id, $msg_id, @args) = @_;
94
return $self->maketext(int($set_id).','.int($msg_id), @args)
98
my ($qq, $qc, $str) = @_;
99
$str =~ s/(\\([ntvbrf\\$qq]))/($2 eq $qc) ? $qc : eval qq("$1")/e;
100
$str =~ s/([\~\[\]])/~$1/g;
108
L<Locale::Maketext>, L<Locale::Maketext::Lexicon>
112
Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
116
Copyright 2002, 2003, 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
118
This program is free software; you can redistribute it and/or
119
modify it under the same terms as Perl itself.
121
See L<http://www.perl.com/perl/misc/Artistic.html>