⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intltool-extract.in

📁 PSlib是一个用来生成PostScript文件的类库。提供了一个生成PostScript文件的简单方法。
💻 IN
📖 第 1 页 / 共 2 页
字号:
	    $translate = 1;	    $nodename =~ s/^_//;	}	my $lookup = '';        $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));        $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));	if ($translate) {	    $lookup = getXMLstring($content, $spacepreserve);            if (!$spacepreserve) {                $lookup =~ s/^\s+//s;                $lookup =~ s/\s+$//s;            }	    if ($lookup && $translate != 2) {                $comments{$lookup} = $XMLCOMMENT if $XMLCOMMENT;                $messages{$lookup} = [];            } elsif ($translate == 2) {                translate_subnodes($fh, \@all, $language, 1, $spacepreserve);	    }	} else {            $XMLCOMMENT = "";	    my $count = scalar(@all);	    if ($count > 0) {                my $index = 0;                while ($index < $count) {                    my $type = $all[$index];                    my $rest = $all[$index+1];                    traverse($fh, $type, $rest, $language, $spacepreserve);                    $index += 2;                }	    }	}        $XMLCOMMENT = "";    }}# Verbatim copy from intltool-merge.in.in, $fh for compatibilitysub parseTree{    my $fh        = shift;    my $ref       = shift;    my $language  = shift || "";    my $name = shift @{ $ref };    my $cont = shift @{ $ref };    while (!$name || "$name" eq "1") {        $name = shift @{ $ref };        $cont = shift @{ $ref };    }    my $spacepreserve = 0;    my $attrs = @{$cont}[0];    $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));    traverse($fh, $name, $cont, $language, $spacepreserve);}# Verbatim copy from intltool-merge.in.insub intltool_tree_comment{    my $expat = shift;    my $data  = $expat->original_string();    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    $data =~ s/^<!--//s;    $data =~ s/-->$//s;    push @$clist, 1 => $data;}# Verbatim copy from intltool-merge.in.insub intltool_tree_cdatastart{    my $expat    = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    push @$clist, 0 => $expat->original_string();}# Verbatim copy from intltool-merge.in.insub intltool_tree_cdataend{    my $expat    = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    $clist->[$pos] .= $expat->original_string();}# Verbatim copy from intltool-merge.in.insub intltool_tree_char{    my $expat = shift;    my $text  = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    # Use original_string so that we retain escaped entities    # in CDATA sections.    #    if ($pos > 0 and $clist->[$pos - 1] eq '0') {        $clist->[$pos] .= $expat->original_string();    } else {        push @$clist, 0 => $expat->original_string();    }}# Verbatim copy from intltool-merge.in.insub intltool_tree_start{    my $expat    = shift;    my $tag      = shift;    my @origlist = ();    # Use original_string so that we retain escaped entities    # in attribute values.  We must convert the string to an    # @origlist array to conform to the structure of the Tree    # Style.    #    my @original_array = split /\x/, $expat->original_string();    my $source         = $expat->original_string();    # Remove leading tag.    #    $source =~ s|^\s*<\s*(\S+)||s;    # Grab attribute key/value pairs and push onto @origlist array.    #    while ($source)    {       if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/)       {           $source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s;           push @origlist, $1;           push @origlist, '"' . $2 . '"';       }       elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/)       {           $source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s;           push @origlist, $1;           push @origlist, "'" . $2 . "'";       }       else       {           last;       }    }    my $ol = [ { @origlist } ];    push @{ $expat->{Lists} }, $expat->{Curlist};    push @{ $expat->{Curlist} }, $tag => $ol;    $expat->{Curlist} = $ol;}# Copied from intltool-merge.in.in and added comment handler.sub readXml{    my $xmldoc = shift || return;    my $ret = eval 'require XML::Parser';    if(!$ret) {        die "You must have XML::Parser installed to run $0\n\n";    }    my $xp = new XML::Parser(Style => 'Tree');    $xp->setHandlers(Char => \&intltool_tree_char);    $xp->setHandlers(Start => \&intltool_tree_start);    $xp->setHandlers(CdataStart => \&intltool_tree_cdatastart);    $xp->setHandlers(CdataEnd => \&intltool_tree_cdataend);    ## differences from intltool-merge.in.in    $xp->setHandlers(Comment => \&intltool_tree_comment);    ## differences end here from intltool-merge.in.in    my $tree = $xp->parse($xmldoc);    #print_var($tree);# <foo><!-- comment --><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo># would be:# [foo, [{}, 1, "comment", head, [{id => "a"}, 0, "Hello ",  em, [{}, 0, "there"]], bar, # [{}, 0, "Howdy",  ref, [{}]], 0, "do" ] ]    return $tree;}sub type_schemas {    ### For schemas XML files ###             # FIXME: We should handle escaped < (less than)    while ($input =~ /                      <locale\ name="C">\s*                          (<default>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/default>\s*)?                          (<short>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/short>\s*)?                          (<long>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/long>\s*)?                      <\/locale>                     /sgx) {        my @totranslate = ($3,$6,$9);        my @eachcomment = ($2,$5,$8);        foreach (@totranslate) {            my $currentcomment = shift @eachcomment;            next if !$_;            s/\s+/ /g;            $messages{entity_decode_minimal($_)} = [];            $comments{entity_decode_minimal($_)} = $currentcomment if (defined($currentcomment));        }    }}sub type_rfc822deb {    ### For rfc822-style Debian configuration files ###    my $lineno = 1;    my $type = '';    while ($input =~ /\G(.*?)(^|\n)(_+)([^:]+):[ \t]*(.*?)(?=\n\S|$)/sg)    {        my ($pre, $newline, $underscore, $tag, $text) = ($1, $2, $3, $4, $5);        while ($pre =~ m/\n/g)        {            $lineno ++;        }        $lineno += length($newline);        my @str_list = rfc822deb_split(length($underscore), $text);        for my $str (@str_list)        {            $strcount++;            $messages{$str} = [];            $loc{$str} = $lineno;            $count{$str} = $strcount;            my $usercomment = '';            while($pre =~ s/(^|\n)#([^\n]*)$//s)            {                $usercomment = "\n" . $2 . $usercomment;            }            $comments{$str} = $tag . $usercomment;        }        $lineno += ($text =~ s/\n//g);    }}sub rfc822deb_split {    # Debian defines a special way to deal with rfc822-style files:    # when a value contain newlines, it consists of    #   1.  a short form (first line)    #   2.  a long description, all lines begin with a space,    #       and paragraphs are separated by a single dot on a line    # This routine returns an array of all paragraphs, and reformat    # them.    # When first argument is 2, the string is a comma separated list of    # values.    my $type = shift;    my $text = shift;    $text =~ s/^[ \t]//mg;    return (split(/, */, $text, 0)) if $type ne 1;    return ($text) if $text !~ /\n/;    $text =~ s/([^\n]*)\n//;    my @list = ($1);    my $str = '';    for my $line (split (/\n/, $text))    {        chomp $line;        if ($line =~ /^\.\s*$/)        {            #  New paragraph            $str =~ s/\s*$//;            push(@list, $str);            $str = '';        }        elsif ($line =~ /^\s/)        {            #  Line which must not be reformatted            $str .= "\n" if length ($str) && $str !~ /\n$/;            $line =~ s/\s+$//;            $str .= $line."\n";        }        else        {            #  Continuation line, remove newline            $str .= " " if length ($str) && $str !~ /\n$/;            $str .= $line;        }    }    $str =~ s/\s*$//;    push(@list, $str) if length ($str);    return @list;}sub type_quoted {    while ($input =~ /\"(([^\"]|\\\")*[^\\\"])\"/g) {        my $message = $1;        my $before = $`;        $message =~ s/\\\"/\"/g;        $before =~ s/[^\n]//g;        $messages{$message} = [];        $loc{$message} = length ($before) + 2;    }}sub type_glade {    ### For translatable Glade XML files ###    my $tags = "label|title|text|format|copyright|comments|preview_text|tooltip|message";    while ($input =~ /<($tags)>([^<]+)<\/($tags)>/sg) {	# Glade sometimes uses tags that normally mark translatable things for        # little bits of non-translatable content. We work around this by not        # translating strings that only includes something like label4 or window1.	$messages{entity_decode($2)} = [] unless $2 =~ /^(window|label|dialog)[0-9]+$/;    }        while ($input =~ /<items>(..[^<]*)<\/items>/sg) {	for my $item (split (/\n/, $1)) {	    $messages{entity_decode($item)} = [];	}    }    ## handle new glade files    while ($input =~ /<(property|atkproperty)\s+[^>]*translatable\s*=\s*"yes"(?:\s+[^>]*comments\s*=\s*"([^"]*)")?[^>]*>([^<]+)<\/\1>/sg) {	$messages{entity_decode($3)} = [] unless $3 =~ /^(window|label)[0-9]+$/;        if (defined($2) and !($3 =~ /^(window|label)[0-9]+$/)) {	   $comments{entity_decode($3)} = entity_decode($2) ;        }    }    while ($input =~ /<atkaction\s+action_name="([^>]*)"\s+description="([^>]+)"\/>/sg) {        $messages{entity_decode_minimal($2)} = [];    }}sub type_scheme {    my ($line, $i, $state, $str, $trcomment, $char);    for $line (split(/\n/, $input)) {        $i = 0;        $state = 0; # 0 - nothing, 1 - string, 2 - translatable string        while ($i < length($line)) {            if (substr($line,$i,1) eq "\"") {                if ($state == 2) {                    $comments{$str} = $trcomment if ($trcomment);                    $messages{$str} = [];                    $str = '';                    $state = 0; $trcomment = "";                } elsif ($state == 1) {                    $str = '';                    $state = 0; $trcomment = "";                } else {                    $state = 1;                    $str = '';                    if ($i>0 && substr($line,$i-1,1) eq '_') {                        $state = 2;                    }                }            } elsif (!$state) {                if (substr($line,$i,1) eq ";") {                    $trcomment = substr($line,$i+1);                    $trcomment =~ s/^;*\s*//;                    $i = length($line);                } elsif ($trcomment && substr($line,$i,1) !~ /\s|\(|\)|_/) {                    $trcomment = "";                }            } else {                if (substr($line,$i,1) eq "\\") {                    $char = substr($line,$i+1,1);                    if ($char ne "\"" && $char ne "\\") {                       $str = $str . "\\";                    }                    $i++;                }                $str = $str . substr($line,$i,1);            }            $i++;        }    }}sub msg_write {    my @msgids;    if (%count)    {        @msgids = sort { $count{$a} <=> $count{$b} } keys %count;    }    else    {        @msgids = sort keys %messages;    }    for my $message (@msgids)    {	my $offsetlines = 1;	$offsetlines++ if $message =~ /%/;	if (defined ($comments{$message}))	{		while ($comments{$message} =~ m/\n/g)		{		    $offsetlines++;		}	}	print OUT "# ".($loc{$message} - $offsetlines).  " \"$FILE\"\n"	        if defined $loc{$message};   	print OUT "/* ".$comments{$message}." */\n"                if defined $comments{$message};   	print OUT "/* xgettext:no-c-format */\n" if $message =~ /%/;            	my @lines = split (/\n/, $message, -1);    	for (my $n = 0; $n < @lines; $n++)	{            if ($n == 0)            { 		print OUT "char *s = N_(\"";             }            else            {                  print OUT "             \"";             }            print OUT escape($lines[$n]);            if ($n < @lines - 1)            {                print OUT "\\n\"\n";             }            else            {                print OUT "\");\n";  	    }        }    }}

⌨️ 快捷键说明

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