[Po4a-commits] "po4a/lib/Locale/Po4a Po.pm,1.87,1.88"
Nicolas FRANCOIS
nekral-guest at alioth.debian.org
Fri Feb 29 19:35:28 UTC 2008
Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory alioth:/tmp/cvs-serv28906/lib/Locale/Po4a
Modified Files:
Po.pm
Log Message:
Add support for writing messages with plural forms. This is not important
for documentation translation, but is needed by other scripts like
msguntypot.
Index: Po.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Po.pm,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- Po.pm 13 Jan 2008 20:48:22 -0000 1.87
+++ Po.pm 29 Feb 2008 19:35:26 -0000 1.88
@@ -377,6 +377,7 @@
print $fh "msgstr ".quote_text($self->{header})."\n\n";
+ my $buf_msgstr_plural; # USed to keep the first msgstr of plural forms
my $first=1;
foreach my $msgid ( sort { ($self->{po}{"$a"}{'pos'}) <=>
($self->{po}{"$b"}{'pos'})
@@ -409,15 +410,46 @@
if defined($self->{po}{$msgid}{'flags'})
&& length ($self->{po}{$msgid}{'flags'});
- if ($self->get_charset =~ /^utf-8$/i) {
- my $msgstr = Encode::decode_utf8($self->{po}{$msgid}{'msgstr'});
- $msgid = Encode::decode_utf8($msgid);
- $output .= Encode::encode_utf8("msgid ".quote_text($msgid)."\n");
- $output .= Encode::encode_utf8("msgstr ".quote_text($msgstr)."\n");
+ if (exists $self->{po}{$msgid}{'plural'}) {
+ if ($self->{po}{$msgid}{'plural'} == 0) {
+ if ($self->get_charset =~ /^utf-8$/i) {
+ my $msgstr = Encode::decode_utf8($self->{po}{$msgid}{'msgstr'});
+ $msgid = Encode::decode_utf8($msgid);
+ $output .= Encode::encode_utf8("msgid ".quote_text($msgid)."\n");
+ $buf_msgstr_plural = Encode::encode_utf8("msgstr[0] ".quote_text($msgstr)."\n");
+ } else {
+ $output = "msgid ".quote_text($msgid)."\n";
+ $buf_msgstr_plural = "msgstr[0] ".quote_text($self->{po}{$msgid}{'msgstr'})."\n";
+ }
+ } elsif ($self->{po}{$msgid}{'plural'} == 1) {
+# TODO: there may be only one plural form
+ if ($self->get_charset =~ /^utf-8$/i) {
+ my $msgstr = Encode::decode_utf8($self->{po}{$msgid}{'msgstr'});
+ $msgid = Encode::decode_utf8($msgid);
+ $output = Encode::encode_utf8("msgid_plural ".quote_text($msgid)."\n");
+ $output .= $buf_msgstr_plural;
+ $output .= Encode::encode_utf8("msgstr[1] ".quote_text($msgstr)."\n");
+ $buf_msgstr_plural = "";
+ } else {
+ $output = "msgid_plural ".quote_text($msgid)."\n";
+ $output .= $buf_msgstr_plural;
+ $output .= "msgstr[1] ".quote_text($self->{po}{$msgid}{'msgstr'})."\n";
+ }
+ } else {
+ die wrap_msg(dgettext("po4a","Can't write PO files with more than two plural forms."));
+ }
} else {
- $output .= "msgid ".quote_text($msgid)."\n";
- $output .= "msgstr ".quote_text($self->{po}{$msgid}{'msgstr'})."\n";
+ if ($self->get_charset =~ /^utf-8$/i) {
+ my $msgstr = Encode::decode_utf8($self->{po}{$msgid}{'msgstr'});
+ $msgid = Encode::decode_utf8($msgid);
+ $output .= Encode::encode_utf8("msgid ".quote_text($msgid)."\n");
+ $output .= Encode::encode_utf8("msgstr ".quote_text($msgstr)."\n");
+ } else {
+ $output .= "msgid ".quote_text($msgid)."\n";
+ $output .= "msgstr ".quote_text($self->{po}{$msgid}{'msgstr'})."\n";
+ }
}
+
print $fh $output;
}
# print STDERR "$fh";
More information about the Po4a-commits
mailing list