diff options
author | Danilo Segan <danilo@canonical.com> | 2011-10-08 21:04:31 +0200 |
---|---|---|
committer | Danilo Segan <danilo@canonical.com> | 2011-10-08 21:04:31 +0200 |
commit | bd3a704f6dbd9e7d493f05cbc68178b03ed39ad5 (patch) | |
tree | 712b652b9c6561639affcf6ba42aaee3f3fca261 | |
parent | c1b3fc2b64aaada233a5d98cf8aba8a00f11ebac (diff) | |
download | intltool-bd3a704f6dbd9e7d493f05cbc68178b03ed39ad5.tar.gz |
Use the same readXml tree parsing for gsettings gschema.xml files like used for XML file support.
-rw-r--r-- | intltool-extract.in | 95 |
1 files changed, 43 insertions, 52 deletions
diff --git a/intltool-extract.in b/intltool-extract.in index a227eb9..94594eb 100644 --- a/intltool-extract.in +++ b/intltool-extract.in @@ -38,7 +38,6 @@ my $VERSION = "@VERSION@"; use strict; use File::Basename; use Getopt::Long; -use XML::Parser; ## Scalars used by the option stuff my $TYPE_ARG = "0"; @@ -639,7 +638,7 @@ sub readXml sub type_schemas { ### For schemas XML files ### - + # FIXME: We should handle escaped < (less than) while ($input =~ / <locale\ name="C">\s* @@ -660,59 +659,51 @@ sub type_schemas { } } - my $content; - my $comment; - my %attrs; - -sub type_gsettings { - - - sub element_start { - shift; shift; - $content = ''; - %attrs = @_; - } - - sub cleanup { - s/^\s+//; - s/\s+$//; - s/\s+/ /g; - return $_; - } - - sub element_end { - my ($expat, $element) = @_; - - if (($element eq 'default' and $attrs{'l10n'}) or - ($element eq 'summary') or ($element eq 'description')) { - $content = (join "\n\n", map cleanup, split/\n\n/, $content); - $content = $attrs{'context'} . "\004" . $content - if $attrs{'context'}; - add_message(entity_decode($content)); - $comments{entity_decode($content)} = $comment - if (defined($comment)); +# Parse the tree as returned by readXml() for gschema.xml files. +sub traverse_gsettings { + my $nodename = shift; + my $content = shift; + my $comment = shift || 0; + my @list = @{ $content }; + my $attrs_ref = shift @list; + my %attrs = %{ $attrs_ref }; + if (($nodename eq 'default' and $attrs{'l10n'}) or + ($nodename eq 'summary') or ($nodename eq 'description')) { + my $message = getXMLstring($content); + my $context = $attrs{'context'}; + $context =~ s/^["'](.*)["']/$1/ if $context; + $message = $context . "\004" . $message if $context; + add_message($message); + $comments{$message} = $comment if $comment; + } else { + my $index = 0; + my $comment; + while (scalar(@list) > 1) { + my $type = shift @list; + my $content = shift @list; + if (!$type || "$type" eq "1") { + if ($type == 1) { + $comment = $content; + } + next; + } else { + traverse_gsettings($type, $content, $comment); + $comment = 0; + } } - undef $comment; - } - - sub comment { - my ($expat, $data) = @_; - $comment = $data; } +} - sub char { - my ($expat, $data) = @_; - $content = $content . $data; - } - - #use Data::Dumper; - #print Dumper readXml($input); print "\n"; - - my $parser = new XML::Parser (Handlers => {Start => \&element_start, - End => \&element_end, - Comment => \&comment, - Char => \&char}); - $parser->parse($input); +sub type_gsettings { + my $tree = readXml($input); + my @tree_nodes = @{ $tree }; + my $node = shift @tree_nodes; + while (!$node || "$node" eq "1") { + shift @tree_nodes; + $node = shift @tree_nodes; + } + my $content = shift @tree_nodes; + traverse_gsettings($node, $content); } sub type_rfc822deb { |