Changeset 5618


Ignore:
Timestamp:
06/26/09 17:28:08 (3 years ago)
Author:
ryan52
Message:

make the interface a bit nicer

Location:
trunk/Locale-Msgfmt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Locale-Msgfmt/Changes

    r5608 r5618  
    11Revision history for Locale-Msgfmt 
     2 
     30.07    Jun 26, 2009 
     4        make the interface a bit nicer 
    25 
    360.06    Jun 26, 2009 
  • trunk/Locale-Msgfmt/bin/msgfmt.pl

    r5528 r5618  
    1010GetOptions("output-file|o=s" => \$opt_o, "use-fuzzy|f" => \$opt_f); 
    1111my $in = shift; 
    12 if(!(defined($in) && defined($opt_o))) { 
    13   print "usage: $0 [-f] -o output.mo input.po\n"; 
    14   exit(1); 
    15 } 
    1612 
    1713msgfmt({in => $in, out => $opt_o, fuzzy => $opt_f}); 
  • trunk/Locale-Msgfmt/lib/Locale/Msgfmt.pm

    r5611 r5618  
    1717sub msgfmt { 
    1818  my $hash = shift; 
     19  if(!defined($hash)) { 
     20    die("error: must give input"); 
     21  } 
     22  if(!(ref($hash) eq "HASH")) { 
     23    $hash = {in => $hash}; 
     24  } 
     25  if(!defined($hash->{in}) or !length($hash->{in})) { 
     26    die("error: must give an input file"); 
     27  } 
     28  if(! -e $hash->{in}) { 
     29    die("error: input does not exist"); 
     30  } 
     31  if(-d $hash->{in}) { 
     32    return _msgfmt_dir($hash); 
     33  } else { 
     34    return _msgfmt($hash); 
     35  } 
     36} 
     37 
     38sub msgfmt_dir { 
     39  return msgfmt(@_); 
     40} 
     41 
     42sub _msgfmt { 
     43  my $hash = shift; 
     44  if(! defined($hash->{in})) { 
     45    die("error: must give an input file"); 
     46  } 
    1947  if(! -f $hash->{in}) { 
    20     print "error: input file does not exist\n"; 
    21     exit(1); 
     48    die("error: input file does not exist"); 
     49  } 
     50  if(! defined($hash->{out})) { 
     51    if($hash->{in} =~ /\.po$/) { 
     52      $hash->{out} = $hash->{in}; 
     53      $hash->{out} =~ s/po$/mo/; 
     54    } else { 
     55      die("error: must give an output file"); 
     56    } 
    2257  } 
    2358  my $mo = Locale::Msgfmt::mo->new(); 
     
    2964} 
    3065 
    31 sub msgfmt_dir { 
     66sub _msgfmt_dir { 
    3267  my $hash = shift; 
    3368  if(! -d $hash->{in}) { 
    34     print "error: input directory does not exist\n"; 
    35     exit(1); 
     69    die("error: input directory does not exist"); 
    3670  } 
    3771  if(! defined($hash->{out})) { 
     
    5791    $newhash{in} = $_; 
    5892    $newhash{out} = $files{$_}; 
    59     msgfmt(\%newhash); 
     93    _msgfmt(\%newhash); 
    6094  } 
    6195} 
     
    75109 
    76110    msgfmt({in => "po/fr.po", out => "po/fr.mo"}); 
    77     msgfmt_dir({in => "po/"}); 
     111    msgfmt({in => "po/fr.po", out => "po/fr.mo", fuzzy => 1}); 
     112    msgfmt("po/"); 
     113    msgfmt({in => "po/", out => "output/"}); 
     114    msgfmt("po/fr.po"); 
     115    msgfmt({in => "po/fr.po", fuzzy => 1}); 
    78116 
    79117=head1 COPYRIGHT & LICENSE 
Note: See TracChangeset for help on using the changeset viewer.