[Bps-public-commit] r17221 - in Locale-Maketext-Lexicon/trunk: . lib/Locale/Maketext lib/Locale/Maketext/Extract/Plugin lib/Locale/Maketext/Lexicon t t/lib/Myi18n

clint at bestpractical.com clint at bestpractical.com
Sun Dec 14 06:56:29 EST 2008


Author: clint
Date: Sun Dec 14 06:56:24 2008
New Revision: 17221

Added:
   Locale-Maketext-Lexicon/trunk/t/7-roundtrip.t   (contents, props changed)
      - copied, changed from r17004, /Locale-Maketext-Lexicon/trunk/t/7-comments.t
   Locale-Maketext-Lexicon/trunk/t/lib/
   Locale-Maketext-Lexicon/trunk/t/lib/Myi18n/
   Locale-Maketext-Lexicon/trunk/t/lib/Myi18n.pm   (contents, props changed)
   Locale-Maketext-Lexicon/trunk/t/lib/Myi18n/en.po
Removed:
   Locale-Maketext-Lexicon/trunk/t/7-comments.t
Modified:
   Locale-Maketext-Lexicon/trunk/Changes
   Locale-Maketext-Lexicon/trunk/MANIFEST
   Locale-Maketext-Lexicon/trunk/MANIFEST.SKIP
   Locale-Maketext-Lexicon/trunk/META.yml
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon/Gettext.pm
   Locale-Maketext-Lexicon/trunk/t/1-basic.t
   Locale-Maketext-Lexicon/trunk/t/5-extract.t
   Locale-Maketext-Lexicon/trunk/t/comments.po

Log:
[Changes for 0.76 - 2008-12-14]

 * Locale::Maketext::Extract / Locale::Maketext::Lexicon::Gettext
   - Roundtripping of fuzzy comments now works. If a translation is marked
     by the translator as fuzzy, then it should remain so when re-extracted
   - Added tests for roundtripping of fuzzy, and for format markers

 * Locale::Maketext::Lexicon
   - Fixed bug http://rt.cpan.org/Public/Bug/Display.html?id=14999
     # relative paths to lang files fail
   - added tests to prove it

 * Locale::Maketext::Extract::Plugin::TT
   - changed the line string to contain only the start line, and not the range
     as this was not consistent with the gettext spec



Modified: Locale-Maketext-Lexicon/trunk/Changes
==============================================================================
--- Locale-Maketext-Lexicon/trunk/Changes	(original)
+++ Locale-Maketext-Lexicon/trunk/Changes	Sun Dec 14 06:56:24 2008
@@ -1,3 +1,19 @@
+[Changes for 0.76 - 2008-12-14]
+
+ * Locale::Maketext::Extract / Locale::Maketext::Lexicon::Gettext
+   - Roundtripping of fuzzy comments now works. If a translation is marked
+     by the translator as fuzzy, then it should remain so when re-extracted
+   - Added tests for roundtripping of fuzzy, and for format markers
+
+ * Locale::Maketext::Lexicon
+   - Fixed bug http://rt.cpan.org/Public/Bug/Display.html?id=14999
+     # relative paths to lang files fail
+   - added tests to prove it
+
+ * Locale::Maketext::Extract::Plugin::TT
+   - changed the line string to contain only the start line, and not the range
+     as this was not consistent with the gettext spec
+
 [Changes for 0.75 - 2008-11-24]
 
  * Locale::Maketext::Extract / Locale::Maketext::Extract::Run

Modified: Locale-Maketext-Lexicon/trunk/MANIFEST
==============================================================================
--- Locale-Maketext-Lexicon/trunk/MANIFEST	(original)
+++ Locale-Maketext-Lexicon/trunk/MANIFEST	Sun Dec 14 06:56:24 2008
@@ -45,12 +45,14 @@
 t/5-extract.t
 t/55-runextract.t
 t/6-gettext.t
-t/7-comments.t
+t/7-roundtrip.t
 t/8-plugin-args.t
 t/9-bug-import-for-subclasses.t
 t/91-pod_test.t
 t/comments.po
 t/gencat.m
+t/lib/Myi18n.pm
+t/lib/Myi18n/en.po
 t/locale/en/LC_MESSAGES/test.mo
 t/locale/en/LC_MESSAGES/test_be.mo
 t/locale/en/LC_MESSAGES/test_utf8.mo

Modified: Locale-Maketext-Lexicon/trunk/MANIFEST.SKIP
==============================================================================
--- Locale-Maketext-Lexicon/trunk/MANIFEST.SKIP	(original)
+++ Locale-Maketext-Lexicon/trunk/MANIFEST.SKIP	Sun Dec 14 06:56:24 2008
@@ -1,4 +1,5 @@
 ^.svn$
+.svn/
 .bak$
 .rej$
 ~$

Modified: Locale-Maketext-Lexicon/trunk/META.yml
==============================================================================
--- Locale-Maketext-Lexicon/trunk/META.yml	(original)
+++ Locale-Maketext-Lexicon/trunk/META.yml	Sun Dec 14 06:56:24 2008
@@ -25,4 +25,4 @@
 requires:
   Locale::Maketext: 0.01
   perl: 5.005
-version: 0.75
+version: 0.76

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm	Sun Dec 14 06:56:24 2008
@@ -1,7 +1,8 @@
 package Locale::Maketext::Extract;
-$Locale::Maketext::Extract::VERSION = '0.33';
+$Locale::Maketext::Extract::VERSION = '0.34';
 
 use strict;
+use Locale::Maketext::Lexicon();
 
 =head1 NAME
 
@@ -256,6 +257,7 @@
     my $plugins = delete $params{plugins}
         || { map { $_ => '*' } keys %Known_Plugins };
 
+    Locale::Maketext::Lexicon::set_option( 'keep_fuzzy' => 1 );
     my $self = bless( {  header           => '',
                          entries          => {},
                          compiled_entries => {},
@@ -334,6 +336,7 @@
     $_[0]->set_header;
     $_[0]->set_lexicon;
     $_[0]->set_comments;
+    $_[0]->set_fuzzy;
     $_[0]->set_entries;
     $_[0]->set_compiled_entries;
 }
@@ -364,16 +367,18 @@
     require Locale::Maketext::Lexicon::Gettext;
     my $lexicon  = {};
     my $comments = {};
+    my $fuzzy    = {};
     $self->set_compiled_entries( {} );
 
     if ( defined($_) ) {
-        ( $lexicon, $comments )
+        ( $lexicon, $comments, $fuzzy )
             = Locale::Maketext::Lexicon::Gettext->parse( $_, <LEXICON> );
     }
 
     # Internally the lexicon is in gettext format already.
     $self->set_lexicon( { map _maketext_to_gettext($_), %$lexicon } );
     $self->set_comments($comments);
+    $self->set_fuzzy($fuzzy);
 
     close LEXICON;
 }
@@ -385,10 +390,18 @@
     return $comment;
 }
 
+sub msg_fuzzy {
+    return $_[0]->{fuzzy}{$_[1]} ? ', fuzzy' : '';
+}
+
 sub set_comments {
     $_[0]->{comments} = $_[1];
 }
 
+sub set_fuzzy {
+    $_[0]->{fuzzy} = $_[1];
+}
+
 =head3 method write_po ($file, $add_format_marker?)
 
 =cut
@@ -412,7 +425,9 @@
         }
         print LEXICON $self->msg_variables($msgid);
         print LEXICON $self->msg_positions($msgid);
-        print LEXICON $self->msg_format($msgid) if $add_format_marker;
+        my $flags = $self->msg_fuzzy($msgid);
+        $flags.= $self->msg_format($msgid) if $add_format_marker;
+        print LEXICON "#$flags\n" if $flags;
         print LEXICON $self->msg_out($msgid);
     }
 
@@ -594,7 +609,7 @@
 
 sub msg_format {
     my ( $self, $msgid ) = @_;
-    return "#, perl-maketext-format\n"
+    return ", perl-maketext-format"
         if $msgid =~ /%(?:[1-9]\d*|\w+\([^\)]*\))/;
     return '';
 }

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm	Sun Dec 14 06:56:24 2008
@@ -168,7 +168,7 @@
         while ( my ( $char, $esc ) = each %Escapes ) {
             $entry->[2] =~ s/$esc/$char/g;
         }
-
+        $entry->[1] =~ s/\D+.*$//;
         $self->add_entry(@$entry);
     }
 }

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm	Sun Dec 14 06:56:24 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon;
-$Locale::Maketext::Lexicon::VERSION = '0.75';
+$Locale::Maketext::Lexicon::VERSION = '0.76';
 
 use 5.004;
 use strict;
@@ -297,7 +297,7 @@
 
             local $@;
             my @content =
-              eval { $class->lexicon_get( $src, scalar caller, $lang ); };
+              eval { $class->lexicon_get( $src, scalar caller(1), $lang ); };
             next if $@ and $@ =~ /^next\b/;
             die $@ if $@;
 

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon/Gettext.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon/Gettext.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon/Gettext.pm	Sun Dec 14 06:56:24 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon::Gettext;
-$Locale::Maketext::Lexicon::Gettext::VERSION = '0.16';
+$Locale::Maketext::Lexicon::Gettext::VERSION = '0.17';
 
 use strict;
 
@@ -85,16 +85,17 @@
 
 =cut
 
-my ($InputEncoding, $OutputEncoding, $DoEncoding);
+my ( $InputEncoding, $OutputEncoding, $DoEncoding );
 
-sub input_encoding  { $InputEncoding }
-sub output_encoding { $OutputEncoding }
+sub input_encoding  {$InputEncoding}
+sub output_encoding {$OutputEncoding}
 
 sub parse {
     my $self = shift;
-    my (%var, $key, @ret);
+    my ( %var, $key, @ret );
     my @metadata;
     my @comments;
+    my @fuzzy;
 
     $InputEncoding = $OutputEncoding = $DoEncoding = undef;
 
@@ -102,63 +103,69 @@
     Carp::cluck "Undefined source called\n" unless defined $_[0];
 
     # Check for magic string of MO files
-    return parse_mo(join('', @_))
-      if ($_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/);
+    return parse_mo( join( '', @_ ) )
+        if ( $_[0] =~ /^\x95\x04\x12\xde/ or $_[0] =~ /^\xde\x12\x04\x95/ );
 
     local $^W;    # no 'uninitialized' warnings, please.
 
     require Locale::Maketext::Lexicon;
-    my $UseFuzzy   = Locale::Maketext::Lexicon::option('use_fuzzy');
+    my $KeepFuzzy = Locale::Maketext::Lexicon::option('keep_fuzzy');
+    my $UseFuzzy  = $KeepFuzzy
+        || Locale::Maketext::Lexicon::option('use_fuzzy');
     my $AllowEmpty = Locale::Maketext::Lexicon::option('allow_empty');
     my $process    = sub {
-        if (length($var{msgstr}) and ($UseFuzzy or !$var{fuzzy})) {
-            push @ret, (map transform($_), @var{ 'msgid', 'msgstr' });
+        if ( length( $var{msgstr} ) and ( $UseFuzzy or !$var{fuzzy} ) ) {
+            push @ret, ( map transform($_), @var{ 'msgid', 'msgstr' } );
         }
         elsif ($AllowEmpty) {
-            push @ret, (transform($var{msgid}), '');
+            push @ret, ( transform( $var{msgid} ), '' );
         }
-        if ($var{msgid} eq '') {
-            push @metadata, parse_metadata($var{msgstr});
-        } else {
-            push  @comments, transform($var{msgid}), $var{msgcomment};
+        if ( $var{msgid} eq '' ) {
+            push @metadata, parse_metadata( $var{msgstr} );
+        }
+        else {
+            push @comments, $var{msgid}, $var{msgcomment};
+        }
+        if ( $KeepFuzzy && $var{fuzzy} ) {
+            push @fuzzy, $var{msgid}, 1;
         }
         %var = ();
     };
 
     # Parse PO files
     foreach (@_) {
-        s/[\015\012]*\z//;    # fix CRLF issues
+        s/[\015\012]*\z//;                  # fix CRLF issues
 
         /^(msgid|msgstr) +"(.*)" *$/
-          ? do {              # leading strings
+            ? do {                          # leading strings
             $var{$1} = $2;
             $key = $1;
-          }
-          :
+            }
+            :
 
-          /^"(.*)" *$/
-          ? do {              # continued strings
+            /^"(.*)" *$/
+            ? do {                          # continued strings
             $var{$key} .= $1;
-          }
-          :
+            }
+            :
 
-          /^# (.*)$/
-          ? do {              # user comments
-              $var{msgcomment} .= $1 . "\n";
-          }
-          :
-
-          /^#, +(.*) *$/
-          ? do {              # control variables
-            $var{$_} = 1 for split(/,\s+/, $1);
-          }
-          :
+            /^# (.*)$/
+            ? do {                          # user comments
+            $var{msgcomment} .= $1 . "\n";
+            }
+            :
+
+            /^#, +(.*) *$/
+            ? do {                          # control variables
+            $var{$_} = 1 for split( /,\s+/, $1 );
+            }
+            :
 
-          /^ *$/ && %var
-          ? do {              # interpolate string escapes
+            /^ *$/ && %var
+            ? do {                          # interpolate string escapes
             $process->($_);
-          }
-          : ();
+            }
+            : ();
 
     }
 
@@ -166,65 +173,65 @@
     $process->() if keys %var != 0;
 
     push @ret, map { transform($_) } @var{ 'msgid', 'msgstr' }
-      if length $var{msgstr};
-    push @metadata, parse_metadata($var{msgstr})
-      if $var{msgid} eq '';
+        if length $var{msgstr};
+    push @metadata, parse_metadata( $var{msgstr} )
+        if $var{msgid} eq '';
 
     return wantarray
-        ? ( { @metadata, @ret }, { @comments } )
-        : ( { @metadata, @ret } )
-        ;
+        ? ( { @metadata, @ret }, {@comments}, {@fuzzy} )
+        : ( { @metadata, @ret } );
 
 }
 
 sub parse_metadata {
     return map {
-            (/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/)
-          ? ($1 eq 'Content-Type')
-              ? do {
-                  my $enc = $2;
-                  if ($enc =~ /\bcharset=\s*([-\w]+)/i) {
-                      $InputEncoding = $1 || '';
-                      $OutputEncoding = Locale::Maketext::Lexicon::encoding()
-                        || '';
-                      $InputEncoding = 'utf8' if $InputEncoding =~ /^utf-?8$/i;
-                      $OutputEncoding = 'utf8'
-                        if $OutputEncoding =~ /^utf-?8$/i;
-                      if (
-                          Locale::Maketext::Lexicon::option('decode')
-                          and ( !$OutputEncoding
-                              or $InputEncoding ne $OutputEncoding)
-                        )
-                      {
-                          require Encode::compat if $] < 5.007001;
-                          require Encode;
-                          $DoEncoding = 1;
-                      }
-                  }
-                  ("__Content-Type", $enc);
-              }
-              : ("__$1", $2)
-          : ();
-    } split(/\r*\n+\r*/, transform(pop));
+              (/^([^\x00-\x1f\x80-\xff :=]+):\s*(.*)$/)
+            ? ( $1 eq 'Content-Type' )
+                ? do {
+                    my $enc = $2;
+                    if ( $enc =~ /\bcharset=\s*([-\w]+)/i ) {
+                        $InputEncoding = $1 || '';
+                        $OutputEncoding
+                            = Locale::Maketext::Lexicon::encoding()
+                            || '';
+                        $InputEncoding = 'utf8'
+                            if $InputEncoding =~ /^utf-?8$/i;
+                        $OutputEncoding = 'utf8'
+                            if $OutputEncoding =~ /^utf-?8$/i;
+                        if ( Locale::Maketext::Lexicon::option('decode')
+                             and (   !$OutputEncoding
+                                   or $InputEncoding ne $OutputEncoding )
+                            )
+                        {
+                            require Encode::compat if $] < 5.007001;
+                            require Encode;
+                            $DoEncoding = 1;
+                        }
+                    }
+                    ( "__Content-Type", $enc );
+                }
+                : ( "__$1", $2 )
+            : ();
+    } split( /\r*\n+\r*/, transform(pop) );
 }
 
 sub transform {
     my $str = shift;
 
-    if ($DoEncoding and $InputEncoding) {
-        $str =
-          ($InputEncoding eq 'utf8')
-          ? Encode::decode_utf8($str)
-          : Encode::decode($InputEncoding, $str);
+    if ( $DoEncoding and $InputEncoding ) {
+        $str
+            = ( $InputEncoding eq 'utf8' )
+            ? Encode::decode_utf8($str)
+            : Encode::decode( $InputEncoding, $str );
     }
 
     $str =~ s/\\([0x]..|c?.)/qq{"\\$1"}/eeg;
 
-    if ($DoEncoding and $OutputEncoding) {
-        $str =
-          ($OutputEncoding eq 'utf8')
-          ? Encode::encode_utf8($str)
-          : Encode::encode($OutputEncoding, $str);
+    if ( $DoEncoding and $OutputEncoding ) {
+        $str
+            = ( $OutputEncoding eq 'utf8' )
+            ? Encode::encode_utf8($str)
+            : Encode::encode( $OutputEncoding, $str );
     }
 
     return _gettext_to_maketext($str);
@@ -251,57 +258,57 @@
 }
 
 sub _unescape {
-    join(',',
-        map { /\A(\s*)%([1-9]\d*|\*)(\s*)\z/ ? "$1_$2$3" : $_ }
-          split(/,/, $_[0]));
+    join( ',',
+          map { /\A(\s*)%([1-9]\d*|\*)(\s*)\z/ ? "$1_$2$3" : $_ }
+              split( /,/, $_[0] ) );
 }
 
 # This subroutine was derived from Locale::Maketext::Gettext::readmo()
 # under the Perl License; the original author is Yi Ma Mao (IMACAT).
 sub parse_mo {
     my $content = shift;
-    my $tmpl = (substr($content, 0, 4) eq "\xde\x12\x04\x95") ? 'V' : 'N';
+    my $tmpl = ( substr( $content, 0, 4 ) eq "\xde\x12\x04\x95" ) ? 'V' : 'N';
 
     # Check the MO format revision number
     # There is only one revision now: revision 0.
-    return if unpack($tmpl, substr($content, 4, 4)) > 0;
+    return if unpack( $tmpl, substr( $content, 4, 4 ) ) > 0;
 
-    my ($num, $offo, $offt);
+    my ( $num, $offo, $offt );
 
     # Number of strings
-    $num = unpack $tmpl, substr($content, 8, 4);
+    $num = unpack $tmpl, substr( $content, 8, 4 );
 
     # Offset to the beginning of the original strings
-    $offo = unpack $tmpl, substr($content, 12, 4);
+    $offo = unpack $tmpl, substr( $content, 12, 4 );
 
     # Offset to the beginning of the translated strings
-    $offt = unpack $tmpl, substr($content, 16, 4);
+    $offt = unpack $tmpl, substr( $content, 16, 4 );
 
-    my (@metadata, @ret);
-    for (0 .. $num - 1) {
-        my ($len, $off, $stro, $strt);
+    my ( @metadata, @ret );
+    for ( 0 .. $num - 1 ) {
+        my ( $len, $off, $stro, $strt );
 
         # The first word is the length of the string
-        $len = unpack $tmpl, substr($content, $offo + $_ * 8, 4);
+        $len = unpack $tmpl, substr( $content, $offo + $_ * 8, 4 );
 
         # The second word is the offset of the string
-        $off = unpack $tmpl, substr($content, $offo + $_ * 8 + 4, 4);
+        $off = unpack $tmpl, substr( $content, $offo + $_ * 8 + 4, 4 );
 
         # Original string
-        $stro = substr($content, $off, $len);
+        $stro = substr( $content, $off, $len );
 
         # The first word is the length of the string
-        $len = unpack $tmpl, substr($content, $offt + $_ * 8, 4);
+        $len = unpack $tmpl, substr( $content, $offt + $_ * 8, 4 );
 
         # The second word is the offset of the string
-        $off = unpack $tmpl, substr($content, $offt + $_ * 8 + 4, 4);
+        $off = unpack $tmpl, substr( $content, $offt + $_ * 8 + 4, 4 );
 
         # Translated string
-        $strt = substr($content, $off, $len);
+        $strt = substr( $content, $off, $len );
 
         # Hash it
         push @metadata, parse_metadata($strt) if $stro eq '';
-        push @ret, (map transform($_), $stro, $strt) if length $strt;
+        push @ret, ( map transform($_), $stro, $strt ) if length $strt;
     }
 
     return { @metadata, @ret };

Modified: Locale-Maketext-Lexicon/trunk/t/1-basic.t
==============================================================================
--- Locale-Maketext-Lexicon/trunk/t/1-basic.t	(original)
+++ Locale-Maketext-Lexicon/trunk/t/1-basic.t	Sun Dec 14 06:56:24 2008
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Test::More tests => 30;
+use Test::More tests => 33;
 
 package Hello::I18N;
 use Test::More;
@@ -9,98 +9,67 @@
 my $warned;
 $SIG{__WARN__} = sub { $warned++ };
 
-use_ok(base => 'Locale::Maketext');
-use_ok(
-    'Locale::Maketext::Lexicon' => {
-	en	=> ['Auto'],
-	fr	=> ['Tie'	=> [ 'Tie::StdHash' ]],
-	de	=> ['Gettext'	=> \*::DATA],
-	zh_tw	=> ['Gettext'	=> 't/messages.mo'],
-	zh_cn	=> ['Msgcat'	=> 't/gencat.m'],
-	zh_hk   => [
-	    'Msgcat'	=> 't/gencat.m',
-	    'Gettext'   => 't/messages.po',
-	],
-    }
+use_ok( base => 'Locale::Maketext' );
+use_ok( 'Locale::Maketext::Lexicon' => {
+                                    en    => ['Auto'],
+                                    fr    => [ 'Tie' => ['Tie::StdHash'] ],
+                                    de    => [ 'Gettext' => \*::DATA ],
+                                    zh_tw => [ 'Gettext' => 't/messages.mo' ],
+                                    zh_cn => [ 'Msgcat' => 't/gencat.m' ],
+                                    zh_hk => [ 'Msgcat'  => 't/gencat.m',
+                                               'Gettext' => 't/messages.po',
+                                    ],
+        }
+);
+
+ok( !$warned, 'no warnings on blank lines' );
+
+Locale::Maketext::Lexicon->import( { de_de      => [ 'Gettext' => \*::DATA ],
+                                     _use_fuzzy => 1,
+                                   }
 );
 
-ok(!$warned, 'no warnings on blank lines');
-
-Locale::Maketext::Lexicon->import({
-    de_de => ['Gettext'	=> \*::DATA],
-    _use_fuzzy => 1,
-});
-
 package main;
 
 ################################################################
 
-ok(my $lh = Hello::I18N->get_handle('en-us'), 'Auto - get_handle');
+ok( my $lh = Hello::I18N->get_handle('en-us'), 'Auto - get_handle' );
 
-is(
-    $lh->maketext('Heute die Welt'),
-    'Heute die Welt',
-    'Auto - autofilling'
-);
+is( $lh->maketext('Heute die Welt'), 'Heute die Welt', 'Auto - autofilling' );
 
 ################################################################
 
-ok($lh = Hello::I18N->get_handle('de'), 'Gettext - get_handle');
+ok( $lh = Hello::I18N->get_handle('de'), 'Gettext - get_handle' );
 
-is(
-    $lh->maketext('Hello, World!'),
-    'Hallo, Welt!',
-    'Gettext - simple case'
-);
-is(
-    $lh->maketext('You have [*,_1,piece] of mail.', 10),
+is( $lh->maketext('Hello, World!'), 'Hallo, Welt!', 'Gettext - simple case' );
+is( $lh->maketext( 'You have [*,_1,piece] of mail.', 10 ),
     'Sie haben 10 Poststuecken.',
-    'Gettext - complex case'
-);
-is(
-    $lh->maketext('[_1] [_2] [_*]', 1, 2, 3),
-    '123 2 1',
-    'Gettext - asterisk interpolation'
-);
-is(
-    $lh->maketext('[_1][_2][_*]', 1, 2, 3),
-    '12321',
-    'Gettext - concatenated variables'
-);
-is(
-    $lh->maketext('[_1]()', 10),
-    '10()',
-    'Gettext - correct parens'
-);
-is(
-    $lh->maketext('__Content-Type'),
+    'Gettext - complex case' );
+is( $lh->maketext( '[_1] [_2] [_*]', 1, 2, 3 ),
+    '123 2 1', 'Gettext - asterisk interpolation' );
+is( $lh->maketext( '[_1][_2][_*]', 1, 2, 3 ),
+    '12321', 'Gettext - concatenated variables' );
+is( $lh->maketext( '[_1]()', 10 ), '10()', 'Gettext - correct parens' );
+is( $lh->maketext('__Content-Type'),
     'text/plain; charset=ISO-8859-1',
     'Gettext - metadata'
 );
-is(
-    $lh->maketext('[_1]()', 10),
-    '10()',
-    'Gettext - correct parens'
-);
-is(
-    $lh->maketext("\n\nKnowledge\nAnd\nNature\n\n"),
-"\n\n".
-"Ich wuenschte recht gelehrt zu werden,\n".
-"Und moechte gern, was auf der Erden\n".
-"Und in dem Himmel ist, erfassen,\n".
-"Die Wissenschaft und die Natur.\n\n",
+is( $lh->maketext( '[_1]()', 10 ), '10()', 'Gettext - correct parens' );
+is( $lh->maketext("\n\nKnowledge\nAnd\nNature\n\n"),
+    "\n\n"
+        . "Ich wuenschte recht gelehrt zu werden,\n"
+        . "Und moechte gern, was auf der Erden\n"
+        . "Und in dem Himmel ist, erfassen,\n"
+        . "Die Wissenschaft und die Natur.\n\n",
     'Gettext - multiline'
 );
 
-is(
-    eval { $lh->maketext("The Hitchhiker's Guide to the Galaxy") },
-    undef,
-    'Gettext - fuzzy entries are ignored'
-);
+is( eval { $lh->maketext("The Hitchhiker's Guide to the Galaxy") },
+    undef, 'Gettext - fuzzy entries are ignored' );
 
-ok($lh = Hello::I18N->get_handle('de_de'), 'Gettext - get_handle on DATA again');
-is(
-    eval { $lh->maketext("The Hitchhiker's Guide to the Galaxy") },
+ok( $lh = Hello::I18N->get_handle('de_de'),
+    'Gettext - get_handle on DATA again' );
+is( eval { $lh->maketext("The Hitchhiker's Guide to the Galaxy") },
     'Der Fuehrer des Trampers zur Galaxie',
     'Gettext - fuzzy entries are recognized with _use_fuzzy'
 );
@@ -108,75 +77,53 @@
 ################################################################
 
 SKIP: {
-    skip("no msgunfmt available", 2) unless `msgunfmt -V` and !$?;
+    skip( "no msgunfmt available", 2 ) unless `msgunfmt -V` and !$?;
 
-    ok($lh = Hello::I18N->get_handle('zh_tw'), 'Gettext - get_handle');
+    ok( $lh = Hello::I18N->get_handle('zh_tw'), 'Gettext - get_handle' );
 
-    is(
-	$lh->maketext('This is a test'),
-	'這是測試',
-	'Gettext - MO File'
-    );
+    is( $lh->maketext('This is a test'), '這是測試',
+        'Gettext - MO File' );
 }
 
 ################################################################
 
-ok($lh = Hello::I18N->get_handle('fr'), 'Tie - get_handle');
-$Hello::I18N::fr::Lexicon{"Good morning"} = 'Bon jour';
+ok( $lh = Hello::I18N->get_handle('fr'), 'Tie - get_handle' );
+$Hello::I18N::fr::Lexicon{"Good morning"}       = 'Bon jour';
 $Hello::I18N::fr::Lexicon{"Good morning, [_1]"} = 'Bon jour, [_1]';
 
-is(
-    $lh->maketext('Good morning'),
-    'Bon jour',
-    'Tie - simple case'
-);
+is( $lh->maketext('Good morning'), 'Bon jour', 'Tie - simple case' );
 
-is(
-    $lh->maketext('Good morning, [_1]', 'Sean'),
+is( $lh->maketext( 'Good morning, [_1]', 'Sean' ),
     'Bon jour, Sean',
-    'Tie - complex case'
-);
+    'Tie - complex case' );
 
 ################################################################
 
-ok($lh = Hello::I18N->get_handle('zh_cn'), 'Msgcat - get_handle');
-is(
-    $lh->maketext(1, 1),
-    'First string',
-    'Msgcat - simple case'
-);
-is(
-    $lh->maketext(1, 2),
-    'Second string',
-    'Msgcat - continued string'
-);
-is(
-    $lh->maketext(1, 3),
-    'Third string',
-    'Msgcat - quote character'
-);
-is(
-    $lh->maketext(1, 4),
+ok( $lh = Hello::I18N->get_handle('zh_cn'), 'Msgcat - get_handle' );
+is( $lh->maketext( 1, 1 ), 'First string',  'Msgcat - simple case' );
+is( $lh->maketext( 1, 2 ), 'Second string', 'Msgcat - continued string' );
+is( $lh->maketext( 1, 3 ), 'Third string',  'Msgcat - quote character' );
+is( $lh->maketext( 1, 4 ),
     'Fourth string',
-    'Msgcat - quote character + continued string'
-);
+    'Msgcat - quote character + continued string' );
 
 ################################################################
 
-ok($lh = Hello::I18N->get_handle('zh_hk'), 'Multiple lexicons - get_handle');
+ok( $lh = Hello::I18N->get_handle('zh_hk'),
+    'Multiple lexicons - get_handle' );
 
-is(
-    $lh->maketext(1, 1),
-    'First string',
-    'Multiple lexicons - first'
-);
+is( $lh->maketext( 1, 1 ), 'First string', 'Multiple lexicons - first' );
 
-is(
-    $lh->maketext('This is a test'),
-    '這是測試',
-    'Multiple lexicons - second'
-);
+is( $lh->maketext('This is a test'),
+    '這是測試', 'Multiple lexicons - second' );
 
+################################################################
+use lib 't/lib/';
+use_ok('Myi18n');
+ok( $lh = Myi18n->get_handle('en'), 'Loaded relative langfile' );
+is( $lh->maketext('Test relative langfiles'),
+    'Relative works!',
+    'Relative langfile trans' );
 
 __DATA__
 msgid ""

Modified: Locale-Maketext-Lexicon/trunk/t/5-extract.t
==============================================================================
--- Locale-Maketext-Lexicon/trunk/t/5-extract.t	(original)
+++ Locale-Maketext-Lexicon/trunk/t/5-extract.t	Sun Dec 14 06:56:24 2008
@@ -178,7 +178,7 @@
 [% END %]
 __TT__
 #. (arg1, arg2)
-#: :1-3
+#: :1
 msgid ""
 "\n"
 "my string\n"
@@ -304,7 +304,7 @@
 [% "my \nstring" |l("my \nstring") %]
 __TT__
 #. ("my \nstring")
-#: :0-1
+#: :0
 msgid ""
 "my \n"
 "string"
@@ -377,7 +377,7 @@
 string[% END %]
 __TT__
 #. ("my \nstring")
-#: :1-2
+#: :1
 msgid ""
 "my\n"
 "string"

Copied: Locale-Maketext-Lexicon/trunk/t/7-roundtrip.t (from r17004, /Locale-Maketext-Lexicon/trunk/t/7-comments.t)
==============================================================================
--- /Locale-Maketext-Lexicon/trunk/t/7-comments.t	(original)
+++ Locale-Maketext-Lexicon/trunk/t/7-roundtrip.t	Sun Dec 14 06:56:24 2008
@@ -4,40 +4,47 @@
 #
 
 use strict;
-use Test::More tests => 6;
+use Test::More tests => 11;
 
 use_ok('Locale::Maketext::Extract');
 
-my $msgid = 'A random string to check that comments work';
+my %msgids = ( comment => 'A random string to check that comments work',
+               fuzzy   => 'Fuzzy flag',
+               marker  => 'Fuzzy plus marker %1'
+);
 my $lex = Locale::Maketext::Extract->new();
-ok( $lex, 'Locale::Maketext::Extract object created');
+ok( $lex, 'Locale::Maketext::Extract object created' );
 
 $lex->read_po('t/comments.po');
 
 # Here '#' and newlines are kept together with the comment
 # Don't know if it's correct or elegant
-is(
-    $lex->msg_comment($msgid),
-    'Some user comment' . "\n"
-);
+is( $lex->msg_comment( $msgids{comment} ), 'Some user comment' . "\n" );
 
-$lex->write_po('t/comments_out.po');
+ok( $lex->msg_fuzzy( $msgids{fuzzy} ),  'Read fuzzy' );
+ok( $lex->msg_fuzzy( $msgids{marker} ), 'Read marker' );
+$lex->write_po( 't/comments_out.po', 1 );
 
 $lex->clear();
 
-is(
-    $lex->msg_comment($msgid),
-    undef,
-    'Comment should be gone with clear()'
-);
+is( $lex->msg_comment( $msgids{comment} ),
+    undef, 'Comment should be gone with clear()' );
+
+ok( !$lex->msg_fuzzy( $msgids{fuzzy} ), 'Fuzzy cleared' );
 
 # Read back the new po file and check that
 # the comment is readable again
 $lex->read_po('t/comments_out.po');
 
-is(
-    $lex->msg_comment($msgid),
-    'Some user comment' . "\n"
-);
-
-ok(unlink('t/comments_out.po'));
+is( $lex->msg_comment( $msgids{comment} ), 'Some user comment' . "\n" );
+ok( $lex->msg_fuzzy( $msgids{fuzzy} ), 'Read fuzzy' );
+my $po;
+{
+    local ( *INPUT, $/ );
+    open( INPUT, 't/comments_out.po' )
+        || die "can't open 't/comments_out.po': $!";
+    $po = <INPUT>;
+}
+ok( $po =~ m/#, fuzzy, perl-maketext-format\nmsgid "Fuzzy plus marker %1"/,
+    'Marker added' );
+ok( unlink('t/comments_out.po') );

Modified: Locale-Maketext-Lexicon/trunk/t/comments.po
==============================================================================
--- Locale-Maketext-Lexicon/trunk/t/comments.po	(original)
+++ Locale-Maketext-Lexicon/trunk/t/comments.po	Sun Dec 14 06:56:24 2008
@@ -13,3 +13,13 @@
 #: comments.t:1
 msgid "A random string to check that comments work"
 msgstr "Una stringa casuale per controllare che i commenti funzionino"
+
+#: comments.t:2
+#, fuzzy
+msgid "Fuzzy flag"
+msgstr "Fuzzy flag trans"
+
+#: comments.t:3
+#, fuzzy
+msgid "Fuzzy plus marker %1"
+msgstr "Fuzzy plus marker %1 trans"

Added: Locale-Maketext-Lexicon/trunk/t/lib/Myi18n.pm
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/trunk/t/lib/Myi18n.pm	Sun Dec 14 06:56:24 2008
@@ -0,0 +1,7 @@
+package Myi18n;
+use base 'Locale::Maketext';
+use Locale::Maketext::Lexicon { 'en'    => [ Gettext => 'en.po' ],
+                                _style => 'gettext',
+};
+
+1

Added: Locale-Maketext-Lexicon/trunk/t/lib/Myi18n/en.po
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/trunk/t/lib/Myi18n/en.po	Sun Dec 14 06:56:24 2008
@@ -0,0 +1,13 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Test App 0.01\n"
+"POT-Creation-Date: 2008-08-01 14:20+0200\n"
+"PO-Revision-Date: 2008-08-01 14:21+0200\n"
+"Last-Translator: <cosimo at cpan.org>\n"
+"Language-Team: Italian <cosimo at cpan.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Test relative langfiles"
+msgstr "Relative works!"



More information about the Bps-public-commit mailing list