intltool-update.in

来自「memprof source code, linux」· IN 代码 · 共 635 行 · 第 1/2 页

IN
635 行
字号
			s-$match.*--;		      }		  }	      }		    if (/_\(QUOTEDTEXT/)	      {		## Remove the first 3 chars and add newline		push @buf_allfiles, unpack("x3 A*", $file) . "\n";		last;	      }	  }	close FILE;      }    foreach my $file (@buf_i18n_xml) {        open FILE, "<$file";        while (<FILE>) {            if (/\s_(.*)=\"/ || /translatable=\"yes\"/){                push @buf_allfiles, unpack("x3 A*", $file) . "\n";                last;            }        }    }    foreach my $file (@buf_i18n_ini){        open FILE, "<$file";        while (<FILE>) {            if (/_(.*)=/){                push @buf_allfiles, unpack("x3 A*", $file) . "\n";                last;            }        }    }    foreach my $file (@buf_i18n_xml_unmarked){        push @buf_allfiles, unpack("x3 A*", $file) . "\n";    }    @buf_allfiles_sorted = sort (@buf_allfiles);    @buf_potfiles_sorted = sort (@buf_potfiles);    my %in2;    foreach (@buf_potfiles_sorted) {        $in2{$_} = 1;    }    my @result;    foreach (@buf_allfiles_sorted){        if (!exists($in2{$_})){            push @result, $_        }    }    ## Save file with information about the files missing    ## if any, and give information about this procedure.    if (@result) {	print "\n" if $VERBOSE;        open OUT, ">missing";        print OUT @result;        print "The following files contain translations and are currently not in use. Please\n";	print "consider adding these to the POTFILES.in file, located in the po/ directory.\n\n";	print @result, "\n";	print "If some of these files are left out on purpose then please add them to\n";	print "POTFILES.skip instead of POTFILES.in. A file 'missing' containing this list\n";        print "of left out files has been written in the current directory.\n";    }    ## If there is nothing to complain about, notify the user    else {        print "\nAll files containing translations are present in POTFILES.in.\n";    }}sub print_error_invalid_option{    ## Handle invalid arguments    print "Try `${PROGRAM} --help' for more information.\n";    exit 1;}sub generate_headers{    my $EXTRACT = `which intltool-extract 2>/dev/null`;    chomp $EXTRACT;    $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"};    ## Generate the .h header files, so we can allow glade and    ## xml translation support    if (! -s $EXTRACT)    {	print "\n *** The intltool-extract script wasn't found!"	     ."\n *** Without it, intltool-update can not generate files.\n";	exit;    }    else    {        open FILE, "<POTFILES.in";        while (<FILE>) {           chomp;           ## Find xml files in POTFILES.in and generate the           ## files with help from the extract script	   my $gettext_type= &determine_type ($1);           if (/\.($xml_extension|$ini_extension)$/ || /^\[/){	       $_ =~ s/^\[[^\[].*]\s*//;               my $filename = "../$_";               if ($VERBOSE){                   system($EXTRACT, "--update", "--type=$gettext_type", $filename);               } else {	 	   system($EXTRACT, "--update", "--type=$gettext_type", "--quiet", $filename);               }           }       }       close FILE;   }}sub generate_po_template{    ## Generate the potfiles from the POTFILES.in file    print "Building the $MODULE.pot...\n" if $VERBOSE;    move ("POTFILES.in", "POTFILES.in.old");    open INFILE, "<POTFILES.in.old";    open OUTFILE, ">POTFILES.in";    while (<INFILE>) {        s/\.($xml_extension|$ini_extension)$/$&.h/;        s/^\[.*]\s*(.*)/$1.h/;        print OUTFILE $_;    }    close OUTFILE;    close INFILE;    system ("xgettext", "--default-domain\=$MODULE", 			"--directory\=\.\.",	   		"--add-comments", 			"--keyword\=\_", 			"--keyword\=N\_", 			"--keyword\=U\_",	   		"--files-from\=\.\/POTFILES\.in");    move ("POTFILES.in.old", "POTFILES.in");    print "Removing generated header (.h) files..." if $VERBOSE;    open FILE, "<POTFILES.in";    while (<FILE>)    {        chomp;        unlink "../$_.h" if /\.($xml_extension|$ini_extension)$/;    }    close FILE;    print "done\n" if $VERBOSE;    if (!-e "$MODULE.po") {        print "WARNING: It seems that none of the files in POTFILES.in ".              "contain marked strings\n";        exit (1);    }    system ("rm", "-f", "$MODULE.pot");    move ("$MODULE.po", "$MODULE.pot") or die "$PROGRAM: couldn't move $MODULE.po to $MODULE.pot.\n";    print "Wrote $MODULE.pot\n" if $VERBOSE;}sub update_po_file{    my ($lang) = @_;    print "Merging $lang.po with $MODULE.pot..." if $VERBOSE;    copy ("$lang.po", "$lang.po.old") || die "copy failed: $!";    # Perform merge, remove backup file and the "messages" trash file     # generated by gettext    system ("msgmerge", "$lang.po.old", "$MODULE.pot", "-o", "$lang.po");    unlink "$lang.po.old";    unlink "messages";}sub print_error_not_existing{    my ($file) = @_;    ## Report error if supplied language file is non-existing    print "$PROGRAM: $file does not exist!\n";    print "Try '$PROGRAM --help' for more information.\n";    exit;}sub gather_po_files{    my @po_files = glob ("./*.po");    @languages = map (&po_file2lang, @po_files);    foreach my $lang (@languages) {	$po_files_by_lang{$lang} = shift (@po_files);    }}sub po_file2lang ($){    my $tmp = $_;    $tmp =~ s/^.*\/(.*)\.po$/$1/;    return $tmp;}sub print_status{    my ($lang) = @_;    system ("msgfmt", "--statistics", "$lang.po");    print "\n";}sub print_report{    &generate_headers;    &generate_po_template;    &gather_po_files;    foreach my $lang (@languages) {	print "$lang: ";	&update_po_file ($lang);    }    print "\n\n * Current translation support in $MODULE \n\n";    foreach my $lang (@languages){        print "$lang: ";	system ("msgfmt", "--statistics", "$lang.po");    }}sub find_package_name{    my $base_dirname = getcwd();    $base_dirname =~ s@.*/@@;    my ($conf_in, $src_dir);    if ($base_dirname =~ /^po(-.+)?$/) {        if (-f "../configure.in") {            $conf_in = "../configure.in";	} elsif (-f "../configure.ac") {	    $conf_in = "../configure.ac";        } else {	    my $makefile_source;	    local (*IN);	    open IN, "<Makefile" || die "can't open Makefile: $!";	    while (<IN>) {		if (/^top_srcdir[ \t]*=/) {		    $src_dir = $_;		    # print "${src_dir}\n";		    $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;		    # print "${src_dir}\n";		    chomp $src_dir;		    $conf_in = "$src_dir" . "/configure.in" . "\n";		    last;		}	    }	    $conf_in || die "Cannot find top_srcdir in Makefile."        }	my %varhash = ();        my $conf_source; {           local (*IN);           open (IN, "<$conf_in") || die "can't open $conf_in: $!";           while (<IN>) {              if (/^(\w+)=(\S+)/) { $varhash{$1} = $2 };           }           seek (IN, 0, 0);           local $/; # slurp mode           $conf_source = <IN>;        }	my $name = "";	$name = $1 if $conf_source =~ /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m;	if ($conf_source =~ /^AC_INIT\([\s\[]*([^,\)\s\]]+)\]?\s*,/m) {	    $name = $1;	    $varhash{"AC_PACKAGE_NAME"} = $1;	}	$name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\s\]]+)/m;	$name = "\$AC_PACKAGE_NAME" if "$name" eq "AC_PACKAGE_NAME";	my $oldname = "";	while (($name =~ /[\$](\S+)/) && ("$oldname" ne "$name")) {	    $oldname = $name;	    if (exists $varhash{$1}) {		$name =~ s/[\$](\S+)/$varhash{$1}/;	    }	}	return $name if $name;    }    print "$PROGRAM: Unable to determine package name.\n" .	  "Make sure to run this script inside the po directory.\n";    exit;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?