[MKDoc-commit] Encoding support for gettext mo/po files (Andrew Rodland)

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Fri Jun 16 15:19:51 BST 2006


Log Message:
-----------
Encoding support for gettext mo/po files (Andrew Rodland)

Modified Files:
--------------
    Petal:
        Changes
    Petal/lib/Petal/TranslationService:
        MOFile.pm

-------------- next part --------------
Index: Changes
===================================================================
RCS file: /var/spool/cvs/Petal/Changes,v
retrieving revision 1.150
retrieving revision 1.151
diff -LChanges -LChanges -u -r1.150 -r1.151
--- Changes
+++ Changes
@@ -7,6 +7,7 @@
     - CACHE_ONLY option (Jonathan Vanasco)
     - Add Digest::MD5 dependency (aaron)
     - Allow passing arguments to coderefs
+    - Encoding support for gettext mo/po files (Andrew Rodland)
 
 2.18 Tue Jan 17 13:01:00 2006
     - $Petal::CodeGenerator::PI_RE should be applied newline insensitively
Index: MOFile.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/TranslationService/MOFile.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -Llib/Petal/TranslationService/MOFile.pm -Llib/Petal/TranslationService/MOFile.pm -u -r1.3 -r1.4
--- lib/Petal/TranslationService/MOFile.pm
+++ lib/Petal/TranslationService/MOFile.pm
@@ -1,5 +1,6 @@
 package Petal::TranslationService::MOFile;
 use Locale::Maketext::Gettext;
+use Encode;
 use strict;
 use warnings;
 
@@ -24,6 +25,8 @@
 
     my $self = bless { file => $file }, $class;
     $self->{lexicon} = { read_mo ($file) };
+
+    ($self->{encoding}) = $self->{lexicon}{""} =~ /^Content-Type: text\/plain; charset=(.*)$/im;
     return $self;
 }
 
@@ -35,7 +38,9 @@
     $self->{lexicon} || return;
     my $res  = $self->{lexicon}->{$id};
 
-    return $res;
+    return undef unless defined $res;
+
+    return decode($self->{encoding}, $res);
 }
 
 


More information about the MKDoc-commit mailing list