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 | ␊ |
12 | package Locale::Po4a::Prop;␊ |
13 | ␊ |
14 | use 5.006;␊ |
15 | use strict;␊ |
16 | use warnings;␊ |
17 | ␊ |
18 | require Exporter;␊ |
19 | ␊ |
20 | use vars qw(@ISA @EXPORT $AUTOLOAD);␊ |
21 | @ISA = qw(Locale::Po4a::TransTractor);␊ |
22 | @EXPORT = qw();␊ |
23 | ␊ |
24 | use Locale::Po4a::TransTractor;␊ |
25 | use Locale::Po4a::Common;␊ |
26 | ␊ |
27 | my $debug=0;␊ |
28 | ␊ |
29 | sub 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 | }␊ |
44 | sub parse {␊ |
45 | ␉my $self=shift;␊ |
46 | ␉my ($line,$ref);␊ |
47 | ␉my $par;␊ |
48 | ␊ |
49 | ␉LINE:␊ |
50 | ␉($line,$ref)=$self->shiftline();␊ |
51 | ␊ |
52 | ␉while (defined($line)) {␊ |
53 | ␉␉chomp($line);␊ |
54 | ␉␉print STDERR "begin:$line\n" if $debug;␊ |
55 | ␊ |
56 | ␉␉if ($line =~ m/("[^"]*")[^=]*=[^"]*"(.*)/) { # "␊ |
57 | ␉␉␉my @paragraph = ();␊ |
58 | ␉␉␉my $pre_text = $1;␊ |
59 | ␉␉␉print STDERR " PreText=".$pre_text."\n" if $debug;␊ |
60 | ␉␉␉my $quoted_text = $2;␊ |
61 | ␉␉␉# The text for translation␊ |
62 | ␉␉␉print STDERR " QuotedText=".$quoted_text."\n" if $debug;␊ |
63 | ␉␉ if ($quoted_text !~ /";[^"]*/) {␊ |
64 | ␉␉␉␉@paragraph = ("$quoted_text\n");␊ |
65 | ␉␉␉␉do {␊ |
66 | ␉␉␉␉␉($line, undef) = $self->shiftline();␊ |
67 | ␉␉␉␉␉push @paragraph, $line;␊ |
68 | ␉␉␉␉} while ($line !~ /";[^"]*/);␊ |
69 | ␉␉␉}␊ |
70 | ␉␉␉if (@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");␊ |
81 | ␉␉␉print STDERR "End of line containing \".\n" if $debug;␊ |
82 | ␉␉}␊ |
83 | else␊ |
84 | ␉␉{␊ |
85 | ␉␉␉print 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 | ␊ |
97 | 1;␊ |
98 | __END__␊ |
99 | ␊ |
100 | =encoding UTF-8␊ |
101 | ␊ |
102 | =head1 NAME␊ |
103 | ␊ |
104 | Locale::Po4a::Prop - convert Java property and OSX/NeXTSTEP strings from/to PO files␊ |
105 | ␊ |
106 | =head1 DESCRIPTION␊ |
107 | ␊ |
108 | Locale::Po4a::Prop is a module to help the translation of Java property and␊ |
109 | OSX/NeXTSTEP strings files into other [human] languages.␊ |
110 | ␊ |
111 | The module searches for lines of the following format and extracts the quoted␊ |
112 | text:␊ |
113 | ␊ |
114 | "identificator"="text than can be translated";␊ |
115 | ␊ |
116 | NOTE: If the text is not quoted, it will be ignored.␊ |
117 | ␊ |
118 | =head1 SEE ALSO␊ |
119 | ␊ |
120 | L<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 | ␊ |
128 | Copyright 2012 by Yves Blusseau␊ |
129 | ␊ |
130 | This program is free software; you may redistribute it and/or modify it␊ |
131 | under the terms of GPL (see the COPYING file).␊ |
132 | ␊ |
133 | =cut␊ |
134 | |