summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Planella <david.planella@ubuntu.com>2013-05-10 03:58:40 +0200
committerDavid Planella <david.planella@ubuntu.com>2013-05-10 03:58:40 +0200
commitb809141c079d0f5c2629a7b6d2b136fd022d3c55 (patch)
treeeeef70c2fadfecd21c9049f74025283f49476b3d
parent751b16f314e021f84c0a6fe554c33aa3ec07c3f1 (diff)
downloadintltool-b809141c079d0f5c2629a7b6d2b136fd022d3c55.tar.gz
Added Qt Designer .ui file extraction support using the internal XML parser
-rw-r--r--intltool-extract.in77
1 files changed, 48 insertions, 29 deletions
diff --git a/intltool-extract.in b/intltool-extract.in
index 779f268..45a969c 100644
--- a/intltool-extract.in
+++ b/intltool-extract.in
@@ -829,6 +829,45 @@ sub type_quotedxml {
}
}
+# Parse the tree as returned by readXml() for Qt Designer .ui files.
+sub traverse_qtdesigner {
+ my $nodename = shift;
+ my $content = shift;
+ my @list = @{ $content };
+ my $attrs_ref = shift @list;
+ my %attrs = %{ $attrs_ref };
+ if ($nodename eq 'string' and !exists $attrs{"notr"}) {
+ # Preserve whitespace. Deal with it ourselves, below.
+ my $message = getXMLstring($content, 1);
+
+ # We strip leading and trailing whitespace but
+ # preserve whitespace within (e.g. newlines)
+ $message =~ s/^\s+//;
+ $message =~ s/\s+$//;
+
+ my $context = $attrs{'comment'};
+ # Remove enclosing quotes from msgctxt
+ $context =~ s/^["'](.*)["']/$1/ if $context;
+ $message = $context . "\004" . $message if $context;
+ add_message($message);
+ my $comment = $attrs{'extracomment'};
+ # Remove enclosing quotes from developer comments
+ $comment =~ s/^["'](.*)["']/$1/ if $comment;
+ $comments{$message} = $comment if $comment;
+ } else {
+ my $index = 0;
+ while (scalar(@list) > 1) {
+ my $type = shift @list;
+ my $content = shift @list;
+ if (!$type || "$type" eq "1") {
+ next;
+ } else {
+ traverse_qtdesigner($type, $content);
+ }
+ }
+ }
+}
+
sub type_qtdesigner {
### For translatable Qt Designer XML files ###
#
@@ -849,36 +888,16 @@ sub type_qtdesigner {
# <string comment="Button" extracomment="TRANSLATORS: refers to the
# action of accepting something">Ok</string>
- # Read all <string> tags one by one and extract the translatable messages
- # within them
- while ($input =~ /<string
- (?:\s+[^>]*notr\s*=\s*"([^"]*)")?
- (?:\s+[^>]*\bcomment\b\s*=\s*"([^"]*)")?
- (?:\s+[^>]*extracomment\s*=\s*"([^"]*)")?
- [^>]*>([^<]+)
- <\/string>/xsg) {
-
- # Skip string if notr="true" (i.e. string marked as non-translatable)
- if (defined($1) && $1 eq "true") {
- next;
- }
-
- # Read translatable message
- my $message = entity_decode($4);
-
- # Add msgctxt to the translatable message if present
- if (defined($2)) {
- $message = entity_decode($2) . "\004" . $message;
- }
-
- # Add message to the array of translatable messages (msgids)
- add_message($message);
-
- # Add developer comment to the comments hash
- if (defined($3)) {
- $comments{$message} = entity_decode($3);
- }
+ 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_qtdesigner($node, $content);
+
}
sub type_glade {