intltool-merge.in

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

IN
658 行
字号
	        $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 "\\\"";    # gettext also handles \n, \t, \b, \r, \f, \v, \a, \xxx (octal),    # \xXX (hex) and has a comment saying they want to handle \u and \U.    return $sequence;}sub unescape_po_string{    my ($string) = @_;    $string =~ s/(\\.)/unescape_one_sequence($1)/eg;    return $string;}sub entity_decode{    local ($_) = @_;    s/&apos;/'/g; # '    s/&quot;/"/g; # "    s/&amp;/&/g;    return $_;}sub entity_encode{    my ($pre_encoded) = @_;    my @list_of_chars = unpack ('C*', $pre_encoded);    if ($PASS_THROUGH_ARG) {        return join ('', map (&entity_encode_int_even_high_bit, @list_of_chars));    } else {        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 chr $_;}sub entity_encode_int_even_high_bit{    if ($_ > 127 || $_ == 34 || $_ == 38 || $_ == 39) {        # the ($_ > 127) should probably be removed	return "&#" . $_ . ";";     } else {	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: $!";    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 codesub xml_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;    # FIXME: support attribute translations    # Empty nodes never need translation, so unmark all of them.    # For example, <_foo/> is just replaced by <foo/>.    $source =~ s|<\s*_($w+)\s*/>|<$1/>|g;    # Support for <_foo>blah</_foo> style translations.    while ($source =~ s|^(.*?)([ \t]*)<\s*_($w+)\s*>(.*?)<\s*/_\3\s*>([ \t]*\n)?||s) {        print OUTPUT $1;        my $spaces = $2;        my $tag = $3;        my $string = $4;	print OUTPUT "$spaces<$tag>$string</$tag>\n";	$string =~ s/\s+/ /g;	$string =~ s/^ //;	$string =~ s/ $//;	$string = entity_decode($string);	for my $lang (sort keys %po_files_by_lang) {	    my $translation = $translations{$lang, $string};	    next if !$translation;	    $translation = entity_encode($translation);	    print OUTPUT "$spaces<$tag xml:lang=\"$lang\">$translation</$tag>\n";        }    }    print OUTPUT $source;    close OUTPUT;}sub keys_merge_translations{    open INPUT, "<${FILE}" or die;    open OUTPUT, ">${OUTFILE}" or die;    while (<INPUT>) {        if (s/^(\s*)_(\w+=(.*))/$1$2/)  {	    my $string = $3;            print OUTPUT;	    my $non_translated_line = $_;            for my $lang (sort keys %po_files_by_lang) {		my $translation = $translations{$lang, $string};                next if !$translation;                $_ = $non_translated_line;		s/(\w+)=.*/[$lang]$1=$translation/;                print OUTPUT;            }	} else {            print OUTPUT;        }    }    close OUTPUT;    close INPUT;}sub desktop_merge_translations{    open INPUT, "<${FILE}" or die;    open OUTPUT, ">${OUTFILE}" or die;    while (<INPUT>) {        if (s/^(\s*)_(\w+=(.*))/$1$2/)  {	    my $string = $3;            print OUTPUT;	    my $non_translated_line = $_;            for my $lang (sort keys %po_files_by_lang) {                my $translation = $translations{$lang, $string};                next if !$translation;                $_ = $non_translated_line;                s/(\w+)=.*/${1}[$lang]=$translation/;                print OUTPUT;            }	} else {            print OUTPUT;        }    }    close OUTPUT;    close INPUT;}sub schemas_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;    # FIXME: support attribute translations    # Empty nodes never need translation, so unmark all of them.    # For example, <_foo/> is just replaced by <foo/>.    $source =~ s|<\s*_($w+)\s*/>|<$1/>|g;    # Support for <_foo>blah</_foo> style translations.    my $regex_start = "^(.*?)([ \t]*)<locale name=\"C\">";    my $regex_short = "([ \t\n]*)<short>(.*?)</short>";    my $regex_long  = "([ \t\n]*)<long>(.*?)</long>";    my $regex_end   = "([ \t\n]*)</locale>";    while ($source =~ s|$regex_start$regex_short$regex_long$regex_end||s) {        print OUTPUT $1;        my $locale_start_spaces = $2;	my $locale_end_spaces = $7;	my $short_spaces = $3;	my $short_string = $4;	my $long_spaces = $5;	my $long_string = $6;	# English first	print OUTPUT "$locale_start_spaces<locale name=\"C\">";	print OUTPUT "$short_spaces<short>$short_string</short>";	print OUTPUT "$long_spaces<long>$long_string</long>";	print OUTPUT "$locale_end_spaces</locale>";	$short_string =~ s/\s+/ /g;	$short_string =~ s/^ //;	$short_string =~ s/ $//;	$short_string = entity_decode($short_string);	$long_string =~ s/\s+/ /g;	$long_string =~ s/^ //;	$long_string =~ s/ $//;	$long_string = entity_decode($long_string);	for my $lang (sort keys %po_files_by_lang) {	    my $short_translation = $translations{$lang, $short_string};	    my $long_translation  = $translations{$lang, $long_string};	    next if (!$short_translation && !$long_translation);	    print OUTPUT "\n$locale_start_spaces<locale name=\"$lang\">";	    if ($short_translation)	    {		$short_translation = entity_encode($short_translation);		print OUTPUT "$short_spaces<short>$short_translation</short>";	    }	    if ($long_translation)	    {		$long_translation = entity_encode($long_translation);		print OUTPUT "$long_spaces<long>$long_translation</long>";	    }	    	    print OUTPUT "$locale_end_spaces</locale>";        }    }    print OUTPUT $source;    close OUTPUT;}

⌨️ 快捷键说明

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