Changeset 5608


Ignore:
Timestamp:
06/26/09 11:58:59 (3 years ago)
Author:
ryan52
Message:

add support for ngettext

Location:
trunk/Locale-Msgfmt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale-Msgfmt/Changes

    r5607 r5608  
    330.06    Jun 26, 2009 
    44        add support for contexts 
     5        add support for ngettext 
    56 
    670.05    Jun 25, 2009 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt/po.pm

    r5607 r5608  
    2929  return if !(defined($h{msgid}) && defined($h{msgstr})); 
    3030  return if ($h{fuzzy} && !$self->{fuzzy} && length($h{msgid}) > 0); 
    31   return if($h{msgstr} eq ""); 
     31  my $msgstr = join Locale::Msgfmt::Utils::null(), @{$h{msgstr}}; 
     32  return if($msgstr eq ""); 
    3233  my $context; 
     34  my $plural; 
    3335  if($h{msgctxt}) { 
    3436    $context = cleanup_string($h{msgctxt}) . Locale::Msgfmt::Utils::eot(); 
     
    3638    $context = ""; 
    3739  } 
    38   $self->{mo}->add_string($context . cleanup_string($h{msgid}), cleanup_string($h{msgstr})); 
     40  if($h{msgid_plural}) { 
     41    $plural = Locale::Msgfmt::Utils::null() . cleanup_string($h{msgid_plural}); 
     42  } else { 
     43    $plural = ""; 
     44  } 
     45  $self->{mo}->add_string($context . cleanup_string($h{msgid}) . $plural, cleanup_string($msgstr)); 
    3946} 
    4047 
     
    4855  while (<F>) { 
    4956    s/\r\n/\n/; 
    50     if(/^(msgid|msgstr|msgctxt) +"(.*)" *$/) { 
     57    if(/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { 
    5158      $type = $1; 
    5259      if(defined($h{$type})) { 
     
    5663      $h{$type} = $2; 
    5764    } 
     65    elsif(/^msgstr(?:\[(\d*)\])? +"(.*)" *$/) { 
     66      $type = "msgstr"; 
     67      if(!$h{$type}) { 
     68        @{$h{$type}} = (); 
     69      } 
     70      push @{$h{$type}}, $2; 
     71    } 
    5872    elsif(/^"(.*)" *$/) { 
    59       $h{$type} .= $1; 
     73      if($type eq "msgstr") { 
     74        @{$h{$type}}[scalar(@{$h{$type}}) - 1] .= $1; 
     75      } else { 
     76        $h{$type} .= $1; 
     77      } 
    6078    } 
    6179    elsif(/^ *$/) { 
  • trunk/Locale-Msgfmt/t/msgfmt.t

    r5607 r5608  
    3232    do_one_test("fr-fr"); 
    3333    do_one_test("context"); 
    34   TODO: { 
    35       local $TODO = "not yet implemented"; 
    36        
    37       do_one_test("ngettext"); 
    38     } 
     34    do_one_test("ngettext"); 
    3935} 
    4036 
Note: See TracChangeset for help on using the changeset viewer.