Changeset 5547


Ignore:
Timestamp:
06/24/09 22:30:16 (3 years ago)
Author:
ryan52
Message:

add a msgfmt_dir function to convert all of the .po files in a directory

Location:
trunk/Locale-Msgfmt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale-Msgfmt/Changes

    r5540 r5547  
    11Revision history for Locale-Msgfmt 
     2 
     30.02    UNRELEASED 
     4        - add a msgfmt_dir function to convert all of the .po files in a directory 
    25 
    360.01    Jun 24, 2009 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt.pm

    r5526 r5547  
    33use Locale::Msgfmt::mo; 
    44use Locale::Msgfmt::po; 
     5use File::Path; 
     6use File::Spec; 
    57 
    68use strict; 
     
    911use base 'Exporter'; 
    1012 
    11 our @EXPORT = qw/msgfmt/; 
     13our @EXPORT = qw/msgfmt msgfmt_dir/; 
    1214 
    1315our $VERSION = '0.01'; 
     
    2729} 
    2830 
     31sub msgfmt_dir { 
     32  my $hash = shift; 
     33  if(! -d $hash->{in}) { 
     34    print "error: input directory does not exist\n"; 
     35    exit(1); 
     36  } 
     37  if(! defined($hash->{out})) { 
     38    $hash->{out} = $hash->{in}; 
     39  } 
     40  if(! -d $hash->{out}) { 
     41    File::Path::mkpath($hash->{out}); 
     42  } 
     43  opendir D, $hash->{in}; 
     44  my @list = readdir D; 
     45  closedir D; 
     46  @list = grep /\.po$/, @list; 
     47  my %files; 
     48  foreach(@list) { 
     49    my $in = File::Spec->catfile($hash->{in}, $_); 
     50    my $out = File::Spec->catfile($hash->{out}, substr($_, 0, -3) . ".mo"); 
     51    $files{$in} = $out; 
     52  } 
     53  delete $hash->{in}; 
     54  delete $hash->{out}; 
     55  foreach(keys %files) { 
     56    my %newhash = (%{$hash}); 
     57    $newhash{in} = $_; 
     58    $newhash{out} = $files{$_}; 
     59    msgfmt(\%newhash); 
     60  } 
     61} 
     62 
    29631; 
    3064 
     
    4074    use Locale::Msgfmt; 
    4175 
    42     msgfmt({in => "po/fr.po", out => "po/fr.mo"}) 
     76    msgfmt({in => "po/fr.po", out => "po/fr.mo"}); 
     77    msgfmt_dir({in => "po/"}); 
    4378 
    4479=head1 COPYRIGHT & LICENSE 
Note: See TracChangeset for help on using the changeset viewer.