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

📄 intltool-merge.in

📁 PSlib是一个用来生成PostScript文件的类库。提供了一个生成PostScript文件的简单方法。
💻 IN
📖 第 1 页 / 共 3 页
字号:
		    $inmsgid = 0;		} else {		    $msgid = unescape_po_string($1);		    $inmsgid = 1;		}		$inmsgstr = 0;		$nextfuzzy = 0;	    }	    if (/^msgstr "((\\.|[^\\]+)*)"/)             {	        $msgstr = unescape_po_string($1);		$inmsgstr = 1;		$inmsgid = 0;	    }	    if (/^"((\\.|[^\\]+)*)"/)             {	        $msgid .= unescape_po_string($1) if $inmsgid;	        $msgstr .= unescape_po_string($1) if $inmsgstr;	    }	}	$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;    }}sub finalize{}sub unescape_one_sequence{    my ($sequence) = @_;    return "\\" if $sequence eq "\\\\";    return "\"" if $sequence eq "\\\"";    return "\n" if $sequence eq "\\n";    return "\r" if $sequence eq "\\r";    return "\t" if $sequence eq "\\t";    return "\b" if $sequence eq "\\b";    return "\f" if $sequence eq "\\f";    return "\a" if $sequence eq "\\a";    return chr(11) if $sequence eq "\\v"; # vertical tab, see ascii(7)    return chr(hex($1)) if ($sequence =~ /\\x([0-9a-fA-F]{2})/);    return chr(oct($1)) if ($sequence =~ /\\([0-7]{3})/);    # FIXME: Is \0 supported as well? Kenneth and Rodney don't want it, see bug #48489    return $sequence;}sub unescape_po_string{    my ($string) = @_;    $string =~ s/(\\x[0-9a-fA-F]{2}|\\[0-7]{3}|\\.)/unescape_one_sequence($1)/eg;    return $string;}sub entity_decode{    local ($_) = @_;    s/&apos;/'/g; # '    s/&quot;/"/g; # "    s/&lt;/</g;    s/&gt;/>/g;    s/&amp;/&/g;    return $_;} # entity_encode: (string)## Encode the given string to XML format (encode '<' etc).sub entity_encode{    my ($pre_encoded) = @_;    my @list_of_chars = unpack ('C*', $pre_encoded);    # with UTF-8 we only encode minimalistic    return join ('', map (&entity_encode_int_minimalist, @list_of_chars));}sub entity_encode_int_minimalist{    return "&quot;" if $_ == 34;    return "&amp;" if $_ == 38;    return "&apos;" if $_ == 39;    return "&lt;" if $_ == 60;    return chr $_;}sub entity_encoded_translation{    my ($lang, $string) = @_;    my $translation = $translations{$lang, $string};    return $string if !$translation;    return entity_encode ($translation);}## XML (bonobo-activation specific) merge codesub ba_merge_translations{    my $source;    {       local $/; # slurp mode       open INPUT, "<$FILE" or die "can't open $FILE: $!";       $source = <INPUT>;       close INPUT;    }    open OUTPUT, ">$OUTFILE" or die "can't open $OUTFILE: $!";    # Binmode so that selftest works ok if using a native Win32 Perl...    binmode (OUTPUT) if $^O eq 'MSWin32';    while ($source =~ s|^(.*?)([ \t]*<\s*$w+\s+($w+\s*=\s*"$q"\s*)+/?>)([ \t]*\n)?||s)     {        print OUTPUT $1;        my $node = $2 . "\n";        my @strings = ();        $_ = $node;	while (s/(\s)_($w+\s*=\s*"($q)")/$1$2/s) {             push @strings, entity_decode($3);        }	print OUTPUT;	my %langs;	for my $string (@strings)         {	    for my $lang (keys %po_files_by_lang)             {                $langs{$lang} = 1 if $translations{$lang, $string};	    }	}		for my $lang (sort keys %langs)         {	    $_ = $node;	    s/(\sname\s*=\s*)"($q)"/$1"$2-$lang"/s;	    s/(\s)_($w+\s*=\s*")($q)"/$1 . $2 . entity_encoded_translation($lang, $3) . '"'/seg;	    print OUTPUT;        }    }    print OUTPUT $source;    close OUTPUT;}## XML (non-bonobo-activation) merge code# Process tag attributes#   Only parameter is a HASH containing attributes -> values mappingsub getAttributeString{    my $sub = shift;    my $do_translate = shift || 0;    my $language = shift || "";    my $result = "";    my $translate = shift;    foreach my $e (reverse(sort(keys %{ $sub }))) {	my $key    = $e;	my $string = $sub->{$e};	my $quote = '"';		$string =~ s/^[\s]+//;	$string =~ s/[\s]+$//;		if ($string =~ /^'.*'$/)	{	    $quote = "'";	}	$string =~ s/^['"]//g;	$string =~ s/['"]$//g;	if ($do_translate && $key =~ /^_/) {	    $key =~ s|^_||g;	    if ($language) {		# Handle translation		my $decode_string = entity_decode($string);		my $translation = $translations{$language, $decode_string};		if ($translation) {		    $translation = entity_encode($translation);		    $string = $translation;                }                $$translate = 2;            } else {                 $$translate = 2 if ($translate && (!$$translate)); # watch not to "overwrite" $translate            }	}		$result .= " $key=$quote$string$quote";    }    return $result;}# Returns a translatable string from XML node, it works on contents of every node in XML::Parser treesub getXMLstring{    my $ref = shift;    my $spacepreserve = shift || 0;    my @list = @{ $ref };    my $result = "";    my $count = scalar(@list);    my $attrs = $list[0];    my $index = 1;    $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));    $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));    while ($index < $count) {	my $type = $list[$index];	my $content = $list[$index+1];        if (! $type ) {	    # We've got CDATA	    if ($content) {		# lets strip the whitespace here, and *ONLY* here                $content =~ s/\s+/ /gs if (!$spacepreserve);		$result .= $content;	    }	} elsif ( "$type" ne "1" ) {	    # We've got another element	    $result .= "<$type";	    $result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements	    if ($content) {		my $subresult = getXMLstring($content, $spacepreserve);		if ($subresult) {		    $result .= ">".$subresult . "</$type>";		} else {		    $result .= "/>";		}	    } else {		$result .= "/>";	    }	}	$index += 2;    }    return $result;}# Translate list of nodes if necessarysub translate_subnodes{    my $fh = shift;    my $content = shift;    my $language = shift || "";    my $singlelang = shift || 0;    my $spacepreserve = shift || 0;    my @nodes = @{ $content };    my $count = scalar(@nodes);    my $index = 0;    while ($index < $count) {        my $type = $nodes[$index];        my $rest = $nodes[$index+1];        if ($singlelang) {            my $oldMO = $MULTIPLE_OUTPUT;            $MULTIPLE_OUTPUT = 1;            traverse($fh, $type, $rest, $language, $spacepreserve);            $MULTIPLE_OUTPUT = $oldMO;        } else {            traverse($fh, $type, $rest, $language, $spacepreserve);        }        $index += 2;    }}sub isWellFormedXmlFragment{    my $ret = eval 'require XML::Parser';    if(!$ret) {        die "You must have XML::Parser installed to run $0\n\n";    }     my $fragment = shift;    return 0 if (!$fragment);    $fragment = "<root>$fragment</root>";    my $xp = new XML::Parser(Style => 'Tree');    my $tree = 0;    eval { $tree = $xp->parse($fragment); };    return $tree;}sub traverse{    my $fh = shift;     my $nodename = shift;    my $content = shift;    my $language = shift || "";    my $spacepreserve = shift || 0;    if (!$nodename) {	if ($content =~ /^[\s]*$/) {	    $leading_space .= $content;	}	print $fh $content;    } else {	# element	my @all = @{ $content };	my $attrs = shift @all;	my $translate = 0;	my $outattr = getAttributeString($attrs, 1, $language, \$translate);	if ($nodename =~ /^_/) {	    $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["']?$/));	print $fh "<$nodename", $outattr;	if ($translate) {	    $lookup = getXMLstring($content, $spacepreserve);            if (!$spacepreserve) {                $lookup =~ s/^\s+//s;                $lookup =~ s/\s+$//s;            }	    if ($lookup || $translate == 2) {                my $translation = $translations{$language, $lookup} if isWellFormedXmlFragment($translations{$language, $lookup});                if ($MULTIPLE_OUTPUT && ($translation || $translate == 2)) {                    $translation = $lookup if (!$translation);                    print $fh " xml:lang=\"", $language, "\"" if $language;                    print $fh ">";                    if ($translate == 2) {                        translate_subnodes($fh, \@all, $language, 1, $spacepreserve);                    } else {                        print $fh $translation;                    }                    print $fh "</$nodename>";                    return; # this means there will be no same translation with xml:lang="$language"...                            # if we want them both, just remove this "return"                } else {                    print $fh ">";                    if ($translate == 2) {                        translate_subnodes($fh, \@all, $language, 1, $spacepreserve);                    } else {                        print $fh $lookup;                    }                    print $fh "</$nodename>";                }	    } else {		print $fh "/>";	    }	    for my $lang (sort keys %po_files_by_lang) {                    if ($MULTIPLE_OUTPUT && $lang ne "$language") {                        next;                    }		    if ($lang) {                        # Handle translation                        #                        my $translate = 0;                        my $localattrs = getAttributeString($attrs, 1, $lang, \$translate);                        my $translation = $translations{$lang, $lookup} if isWellFormedXmlFragment($translations{$lang, $lookup});                        if ($translate && !$translation) {                            $translation = $lookup;                        }                        if ($translation || $translate) {			    print $fh "\n";			    $leading_space =~ s/.*\n//g;			    print $fh $leading_space; 			    print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs, ">";                            if ($translate == 2) {                               translate_subnodes($fh, \@all, $lang, 1, $spacepreserve);                            } else {                                print $fh $translation;                            }                            print $fh "</$nodename>";			}                    }	    }	} else {	    my $count = scalar(@all);	    if ($count > 0) {		print $fh ">";                my $index = 0;                while ($index < $count) {                    my $type = $all[$index];                    my $rest = $all[$index+1];                    traverse($fh, $type, $rest, $language, $spacepreserve);                    $index += 2;                }		print $fh "</$nodename>";	    } else {		print $fh "/>";	    }	}    }}sub intltool_tree_comment{    my $expat = shift;    my $data  = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    push @$clist, 1 => $data;}sub intltool_tree_cdatastart{    my $expat    = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    push @$clist, 0 => $expat->original_string();}sub intltool_tree_cdataend{    my $expat    = shift;    my $clist = $expat->{Curlist};    my $pos   = $#$clist;    $clist->[$pos] .= $expat->original_string();}sub 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();    }}sub 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 . '"';       }

⌨️ 快捷键说明

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