CIPP

 view release on metacpan or  search on metacpan

bin/cipp-l10n  view on Meta::CPAN

        unless -f $file && -r $file;
    
    my $data = do $file;
    
    $verbose && print STDERR "Done\n";
    
    return $data;
}

sub assign_files_to_domains {
    my ($files, $conf) = @_;
    
    my @files = sort @{$files};

    $verbose && print STDERR "Number of files ".@files."\n";
    
    foreach my $base ( sort { length($b) <=> length($a) } keys %{$conf} ) {
        my $domain = $conf->{$base}->{domain};
        $verbose && print STDERR "Assigning files in '$base/' to domain '$domain'...\n";
        my $base_qm = quotemeta $base;
        my $base_regex = qr[^$base_qm];
        my $i = 0;
        my $start_idx = -1;
        my $stop_idx  = @{$files};
        foreach my $file ( @files ) {
            if ( $file =~ $base_regex ) {
                $start_idx = $i if $start_idx == -1;
            }
            else {
                if ( $start_idx != -1 ) {
                    $stop_idx = $i;
                    last;
                }
            }
            ++$i;
        }
        if ( $start_idx == -1 ) {
            die "No matching files for '$base'";
        }
        my @matched_files = splice(@files, $start_idx, $stop_idx-$start_idx);
        $conf->{$base}->{files} = \@matched_files;
    }
    
}

sub write_pot_for_all_domains {
    my ($conf, $ns_root_dir) = @_;
    
    foreach my $base ( sort { length($b) <=> length($a) } keys %{$conf} ) {
        my $domain_conf = $conf->{$base};
        my $domain   = $domain_conf->{domain};
        my $messages = get_messages($conf->{$base}->{files}, "");
        my $pot_file = "$ns_root_dir/tmp/l10n/$domain.pot";
        create_dir_for($pot_file);
        save_po_file($messages, $pot_file, $domain_conf);
    }
    
    1;
}

sub update_po_for_all_domains {
    my ($conf, $ns_root_dir) = @_;
    
    my $ns_prod_dir = "$ns_root_dir/prod";
    my $ns_tmp_dir  = "$ns_root_dir/tmp";

    foreach my $base ( keys %{$conf} ) {
        my $dom_conf = $conf->{$base};
        my $domain   = $dom_conf->{domain};
        my $domain_file = $domain;
        $domain_file =~ s/\./-/g;
        foreach my $lang ( @{$dom_conf->{lang}} ) {
            my $po_file  = "$ns_root_dir/$base/$dom_conf->{po_dir}/$domain_file-$lang.po";
            my $pot_file = "$ns_tmp_dir/l10n/$domain.pot";
            if ( ! -e $po_file || 0 == -s $po_file ) {
                $verbose && print STDERR "Copying .pot file '$pot_file' to '$po_file'... ";
                copy($pot_file, $po_file) or die "can't copy '$pot_file' to '$po_file'";
                $verbose && print STDERR "Done\n";
            }
            else {
                $verbose && print STDERR "Updating .po file '$po_file'... ";
                my $cmd =
                    "msgmerge -o $po_file.tmp $po_file $pot_file && ".
                    "mv $po_file.tmp $po_file && echo SUCCESS";
                run($cmd);
                $verbose && print STDERR "Done\n";
            }
        }
    }
    
    1;
}

sub msgfmt_for_all_domains {
    my ($conf, $ns_root_dir) = @_;
    
    my $ns_prod_dir = "$ns_root_dir/prod";
    my $ns_tmp_dir  = "$ns_root_dir/tmp";

    foreach my $base ( keys %{$conf} ) {
        my $dom_conf = $conf->{$base};
        my $domain   = $dom_conf->{domain};
        my $domain_file = $domain;
        $domain_file =~ s/\./-/g;
        foreach my $lang ( @{$dom_conf->{lang}} ) {
            my $mo_file  = "$ns_prod_dir/l10n/$lang/LC_MESSAGES/$domain.mo";
            my $po_file  = "$ns_root_dir/$base/$dom_conf->{po_dir}/$domain_file-$lang.po";
            my $cmd = "msgfmt --statistics -c -o $mo_file $po_file && echo SUCCESS";
            create_dir_for($mo_file);
            $verbose && print STDERR "Installing .mo file '$mo_file'...\n";
            run($cmd, 1);
        }
    }
    
    1;
}

sub run {
    my ($cmd, $show_output) = @_;
    my $output = qx[($cmd) 2>&1];
    if ( $output !~ /SUCCESS/ ) {



( run in 0.735 second using v1.01-cache-2.11-cpan-13bb782fe5a )