Federico Bruni:
> Il giorno ven 21 apr 2017 alle 7:08, Federico Bruni 
> <f...@inventati.org> ha scritto:
> > I guess I'll have to revert to my almost manual replacement I've used 
> > so far.
> 
> Or I may try a  different approach and script a replacement from a file 
> like:
> 
> @ref{Different editions from one source},@ref{Edizioni diverse da un 
> unico sorgente}
> @ref{Dimensions},@ref{Dimensioni}
> @ref{Direction and placement},@ref{Direzione e posizionamento}
> 
> that replace first instance of @ref with the second instance (after the 
> comma)

Well, that is about the same as putting the translation in the po file 
and running the attached script. Then if and when gettext is working 
again for doc., as someone said it has been, then you don't have to 
convert your replacement file to po style.

$ read_po.pl Documentation/po/it.po .itely | head
File: Documentation/essay/engraving.itely
 @ref{Music engraving} -> @ref{}
 @ref{The LilyPond story} -> @ref{}
 @ref{Engraving details} -> @ref{}
 @ref{Music fonts} -> @ref{}
 @ref{Optical spacing} -> @ref{}
 @ref{Ledger lines} -> @ref{}
 @ref{Optical sizing} -> @ref{}
 @ref{Why work so hard?} -> @ref{}
 @ref{Automated engraving} -> @ref{}
$

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my %file_list;

sub read_po() {
    my $po_file = $ARGV[0];
    my @arr;

    open(FH, $po_file) || die("cannot open $po_file");

    my $nxt = [ [], "", "" ];

    while (<FH>) {
	chomp;
	s/^\s*//;
	s/\s*$//;

	if (m/^$/) {
	    my %file;
	    my @lst;
	    for my $r (@{$$nxt[0]}) {
		next if ($r =~ m|Documentation/cs/|);
		if ($r =~ m| in (Documentation/.*\.itely)$|) {
		    $file{$1} = 1;
		}
		push @lst, $r;
	    }
	    my @Keys = sort keys %file;
	    if (@Keys) {
		$$nxt[0] = [ @lst ];
		push @arr, $nxt;
		for my $f (@Keys) {
		    if (!defined($file_list{$f})) {
			$file_list{$f} = [];
		    }
		    my $r = [ $$nxt[1], $$nxt[2] ];
		    push @{$file_list{$f}}, $r;
		}
	    }
	    $nxt = [ [], "", "" ];
	    next;
	}

	if (m/^\#/) {
	    push @{$$nxt[0]}, $_;
	    next;
	}

	if (m/^msgid\s*\"(.*)\"$/) {
	    my $str = $1;
	    $$nxt[1] = $str;
	    next;
	}

	if (m/^msgstr\s*\"(.*)\"$/) {
	    my $str = $1;
	    $$nxt[2] = $str;
	    next;
	}

	if (m/^\"(.*)\"$/) {
	    my $str = $1;
	    if ($$nxt[2] eq "") {
		$$nxt[1] .= $str;
	    } else {
		$$nxt[2] .= $str;
	    }
	    next;
	}

	warn("unhandled data: <$_>");
    }

    close(FH);
    @arr;
}

sub print_arr(@) {
    my @arr = @_;

    for my $r (@arr) {
	print join("\n", @{$$r[0]}), "\n";
	print "msgid \"$$r[1]\"\n";
	print "msgstr \"$$r[2]\"\n";
	print "\n";
    }
}

sub mk_subst(@) {
    my @arr = @_;

    #print Dumper(\%file_list);
    my @k = sort keys %file_list;
    for my $k (@k) {
	my @val = @{$file_list{$k}};
	print "File: $k\n";
	for my $r (@val) {
	    print " \@ref{$$r[0]} -> \@ref{$$r[1]}\n";
	}
	print "\n";
    }
}

sub main() {
    my @arr = read_po();
    #print_arr(@arr);
    mk_subst();
}

main();
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to