[Po4a-devel][CVS] po4a/lib/Locale/Po4a Po.pm,1.19,1.20

Jordi Vilalta po4a-devel@lists.alioth.debian.org
Sun, 08 Aug 2004 06:30:58 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv23028

Modified Files:
	Po.pm 
Log Message:
Added a new function that recodes the whole po to utf (needed by the future
po4a-update)


Index: Po.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Po.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Po.pm	7 Aug 2004 04:51:33 -0000	1.19
+++ Po.pm	8 Aug 2004 06:30:56 -0000	1.20
@@ -74,6 +74,8 @@
 use Locale::gettext qw(dgettext);
 use File::Path; # mkdir before write
 
+use Encode;
+
 my @known_flags=qw(wrap no-wrap c-format fuzzy);
 
 my %debug=('canonize'	=> 0,
@@ -551,6 +553,28 @@
 	       if (apply($msgid,$msgstr,$ref,$flags,$comment,$automatic)); # DO NOT CHANGE THE ORDER
     }
     return $res;
+}
+
+=item to_utf()
+
+This recodes all the msgstrs in the po from the character set specified in the
+header to utf-8. This process is only ignored if the header character set is
+"CHARSET" (unspecified, usually means ascii), "ascii" or "utf-8".
+
+=cut
+
+sub to_utf { 
+    my $this = shift;
+    my $charset = $this->get_charset();
+
+    unless ($charset eq "CHARSET" or
+	    $charset eq "ascii" or
+	    $charset eq "utf-8") {
+	foreach my $msgid ( keys %{$this->{po}} ) {
+	    Encode::from_to($this->{po}{$msgid}{'msgstr'}, $charset, "utf-8");
+	}
+	$this->set_charset("utf-8");
+    }
 }
 
 =back