Chameleon

Chameleon Svn Source Tree

Root/trunk/package/bin/po4a/lib/Locale/Po4a/Prop.pm

1# Locale::Po4a::Prop -- Convert Java property and OSX/NeXTSTEP strings files
2# to PO file, for translation.
3#
4# This program is free software; you may redistribute it and/or modify it
5# under the terms of GPL (see COPYING).
6#
7
8############################################################################
9# Modules and declarations
10############################################################################
11
12package Locale::Po4a::Prop;
13
14use 5.006;
15use strict;
16use warnings;
17
18require Exporter;
19
20use vars qw(@ISA @EXPORT $AUTOLOAD);
21@ISA = qw(Locale::Po4a::TransTractor);
22@EXPORT = qw();
23
24use Locale::Po4a::TransTractor;
25use Locale::Po4a::Common;
26
27my $debug=0;
28
29sub initialize {
30 my $self = shift;
31 my %options = @_;
32
33 $self->{options}{'wrap'}=0;
34
35 foreach my $opt (keys %options) {
36 if ($options{$opt}) {
37 die wrap_mod("po4a::prop",
38 dgettext("po4a", "Unknown option: %s"), $opt)
39 unless exists $self->{options}{$opt};
40 $self->{options}{$opt} = $options{$opt};
41 }
42 }
43}
44sub parse {
45my $self=shift;
46my ($line,$ref);
47my $par;
48
49LINE:
50($line,$ref)=$self->shiftline();
51
52while (defined($line)) {
53chomp($line);
54print STDERR "begin:$line\n" if $debug;
55
56if ($line =~ m/("[^"]*")[^=]*=[^"]*"(.*)/) { # "
57my @paragraph = ();
58my $pre_text = $1;
59print STDERR " PreText=".$pre_text."\n" if $debug;
60my $quoted_text = $2;
61# The text for translation
62print STDERR " QuotedText=".$quoted_text."\n" if $debug;
63 if ($quoted_text !~ /";[^"]*/) {
64@paragraph = ("$quoted_text\n");
65do {
66($line, undef) = $self->shiftline();
67push @paragraph, $line;
68} while ($line !~ /";[^"]*/);
69}
70if (@paragraph) {
71$quoted_text = join('', @paragraph);
72}
73
74 # Remove the final ";
75 $quoted_text =~ s/"\s*;[^"]*$//;
76 # Translate the string
77 $par = $self->translate($quoted_text, $ref, $pre_text,
78 'wrap'=>$self->{options}{'wrap'});
79# Now push the result
80 $self->pushline($pre_text .' = "'.$par."\";\n");
81print STDERR "End of line containing \".\n" if $debug;
82}
83 else
84{
85print STDERR "Other stuff\n" if $debug;
86$self->pushline("$line\n");
87}
88# Reinit the loop
89($line,$ref)=$self->shiftline();
90}
91}
92
93##############################################################################
94# Module return value and documentation
95##############################################################################
96
971;
98__END__
99
100=encoding UTF-8
101
102=head1 NAME
103
104Locale::Po4a::Prop - convert Java property and OSX/NeXTSTEP strings from/to PO files
105
106=head1 DESCRIPTION
107
108Locale::Po4a::Prop is a module to help the translation of Java property and
109OSX/NeXTSTEP strings files into other [human] languages.
110
111The module searches for lines of the following format and extracts the quoted
112text:
113
114"identificator"="text than can be translated";
115
116NOTE: If the text is not quoted, it will be ignored.
117
118=head1 SEE ALSO
119
120L<Locale::Po4a::TransTractor(3pm)>, L<po4a(7)|po4a.7>
121
122=head1 AUTHORS
123
124 Yves Blusseau <aphc549cmv@snkmail.com>
125
126=head1 COPYRIGHT AND LICENSE
127
128Copyright 2012 by Yves Blusseau
129
130This program is free software; you may redistribute it and/or modify it
131under the terms of GPL (see the COPYING file).
132
133=cut
134

Archive Download this file

Revision: 1865