summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanilo Šegan <danilo@segan.org>2014-02-12 00:26:48 +0100
committerDanilo Šegan <danilo@segan.org>2014-02-12 00:26:48 +0100
commited6c420be52e994efd8304dace2c7b5f3913c23f (patch)
treec9fad7a1e66d84658b9c7aa8b2ccd449f8edc009
parent2c08e9d2afef0079158ce7a7b13023b9230635e2 (diff)
parent7b401b2ba496fd6a583ad3fdc64ae1f2ff9e01f1 (diff)
downloadintltool-ed6c420be52e994efd8304dace2c7b5f3913c23f.tar.gz
Merge David's branch ~dpm/intltool/add-qtdesigner-support.
-rw-r--r--doc/intltool-extract.82
-rw-r--r--intltool-extract.in74
-rw-r--r--tests/cases/Makefile.am2
-rw-r--r--tests/cases/extract-qtdesigner.ui210
-rw-r--r--tests/results/Makefile.am1
-rw-r--r--tests/results/extract-qtdesigner.ui.h13
-rwxr-xr-xtests/selftest.pl.in5
7 files changed, 306 insertions, 1 deletions
diff --git a/doc/intltool-extract.8 b/doc/intltool-extract.8
index 1cccda7..dd1569e 100644
--- a/doc/intltool-extract.8
+++ b/doc/intltool-extract.8
@@ -54,6 +54,8 @@ Specify the type of source file. Currently supported types are:
"gettext/scheme" (.scm)
.br
"gettext/xml" (Generic XML file)
+.br
+"gettext/qtdesigner" (Qt Designer .ui files)
.IP "\fB\-v\fR" 4
.PD 0
.IP "\fB\-\-version\fR" 4
diff --git a/intltool-extract.in b/intltool-extract.in
index 6e9c3cf..45a969c 100644
--- a/intltool-extract.in
+++ b/intltool-extract.in
@@ -165,7 +165,7 @@ XML files. Read manpage (man ${PROGRAM}) for more info.
"gettext/glade", "gettext/ini", "gettext/keys"
"gettext/rfc822deb", "gettext/schemas",
"gettext/gsettings", "gettext/xml", "gettext/quoted",
- "gettext/quotedxml", "gettext/tlk"
+ "gettext/quotedxml", "gettext/tlk", "gettext/qtdesigner"
-l, --local Writes output into current working directory
(conflicts with --update)
--update Writes output into the same directory the source file
@@ -225,6 +225,7 @@ sub convert {
&type_quoted if $gettext_type eq "quoted";
&type_quotedxml if $gettext_type eq "quotedxml";
&type_tlk if $gettext_type eq "tlk";
+ &type_qtdesigner if $gettext_type eq "qtdesigner";
}
sub entity_decode_minimal
@@ -828,6 +829,77 @@ 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 ###
+ #
+ # Specs:
+ #
+ # - http://qt-project.org/doc/qt-5.0/qtlinguist/linguist-ts-file-format.html
+ # - http://qt-project.org/doc/qt-5.0/qtdesigner/designer-ui-file-format.html
+ #
+ # <string> tag attributes:
+ #
+ # notr="true" means the string is not translatable
+ # extracomment maps to a developer comment in gettext
+ # comment corresponds to "disambiguation" in the Qt Linguist API, and maps
+ # to msgctxt in gettext
+ #
+ # Example:
+ #
+ # <string comment="Button" extracomment="TRANSLATORS: refers to the
+ # action of accepting something">Ok</string>
+
+ 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 {
### For translatable Glade XML files ###
diff --git a/tests/cases/Makefile.am b/tests/cases/Makefile.am
index 904b52a..10210f2 100644
--- a/tests/cases/Makefile.am
+++ b/tests/cases/Makefile.am
@@ -17,6 +17,7 @@ EXTRA_DIST = \
extract8.glade \
extract9.po \
extract9.xml.in \
+ extract-qtdesigner.ui \
fr.po \
fr_BE.po \
fr_FR.po \
@@ -60,6 +61,7 @@ CLEANFILES = \
extract14.xml.in.h \
extract9.xml \
extract9.xml.in.h \
+ extract-qtdesigner.ui.h \
gsettings.gschema.xml.h \
iso88591text.xml.in.h \
merge-cdata.xml \
diff --git a/tests/cases/extract-qtdesigner.ui b/tests/cases/extract-qtdesigner.ui
new file mode 100644
index 0000000..7c16560
--- /dev/null
+++ b/tests/cases/extract-qtdesigner.ui
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>main</class>
+ <widget class="QWidget" name="main">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>640</width>
+ <height>457</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tabWelcome">
+ <attribute name="title">
+ <string notr="true">Do not translate this</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QWidget" name="welcomeTop" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>100</height>
+ </size>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QWidget" name="welcomeTopText" native="true">
+ <widget class="QLabel" name="welcomeLabel">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>20</y>
+ <width>330</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Ubuntu</family>
+ <pointsize>21</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string extracomment="TRANSLATORS: this is the main title of the authentication dialog">This is a translatable title</string>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="welcomeBottom" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <widget class="QTextEdit" name="welcomeTextBox">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>20</y>
+ <width>571</width>
+ <height>181</height>
+ </rect>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="html">
+ <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;title&gt;HTML document extraction test&lt;/title&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Once upon a time, in a galaxy far, far away... &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="friendlyTestsButton">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>210</y>
+ <width>571</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>9</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string comment="Button" extracomment="TRANSLATORS: refers to the action of accepting something">Ok</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="checkBox">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>280</y>
+ <width>321</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Ubuntu</family>
+ </font>
+ </property>
+ <property name="text">
+ <string comment="WelcomeDialog">Don't show me this message in the future</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="checkBox_2">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>260</y>
+ <width>321</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Ubuntu</family>
+ </font>
+ </property>
+ <property name="text">
+ <string extracomment="TRANSLATORS: authentication is required to perform this action">Require authentication</string>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/results/Makefile.am b/tests/results/Makefile.am
index c5090ba..97501fb 100644
--- a/tests/results/Makefile.am
+++ b/tests/results/Makefile.am
@@ -18,6 +18,7 @@ EXTRA_DIST = \
extract14.xml.in.h \
extract-gtkbuilder.ui.h \
extract-gtkbuilder-single.ui.h \
+ extract-qtdesigner.ui.h \
gsettings.gschema.xml.h \
iso88591text.xml.in.h \
merge-cdata.xml \
diff --git a/tests/results/extract-qtdesigner.ui.h b/tests/results/extract-qtdesigner.ui.h
new file mode 100644
index 0000000..dd85ea1
--- /dev/null
+++ b/tests/results/extract-qtdesigner.ui.h
@@ -0,0 +1,13 @@
+char *s = N_("Form");
+/* TRANSLATORS: this is the main title of the authentication dialog */
+char *s = N_("This is a translatable title");
+char *s = N_("&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;\n"
+ "&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;title&gt;HTML document extraction test&lt;/title&gt;&lt;style type=&quot;text/css&quot;&gt;\n"
+ "p, li { white-space: pre-wrap; }\n"
+ "&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;\n"
+ "&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Once upon a time, in a galaxy far, far away... &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;");
+/* TRANSLATORS: refers to the action of accepting something */
+char *s = C_("Button", "Ok");
+char *s = C_("WelcomeDialog", "Don't show me this message in the future");
+/* TRANSLATORS: authentication is required to perform this action */
+char *s = N_("Require authentication");
diff --git a/tests/selftest.pl.in b/tests/selftest.pl.in
index 8746f9b..69aba59 100755
--- a/tests/selftest.pl.in
+++ b/tests/selftest.pl.in
@@ -294,6 +294,11 @@ $case = "extract-gtkbuilder-single.ui";
system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);
+print "40. Extract messages from a Qt Designer UI file: ";
+$case = "extract-qtdesigner.ui";
+system("$INTLTOOL_EXTRACT --type=gettext/qtdesigner --quiet --update cases/$case") == 0 or $failed = 1;
+check_extract_result($case);
+
system("rm -f cases/*.*") if $srcdir ne ".";
system("rm -rf C az extract9 fr fr_BE fr_FR merge6 schemasmerge1 schemasmerge2 spacepreserve test test-quoted merge6.xml");