summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Planella <david.planella@ubuntu.com>2012-03-12 20:20:59 +0100
committerDavid Planella <david.planella@ubuntu.com>2012-03-12 20:20:59 +0100
commitc4150e875a0531fe2ff5de4f18c53d68088cc211 (patch)
treeeb289c9c7df41388ddf9a0397478a0dff51c63c3
parenta4c6775b120d48278dc10234c326878ab42a035b (diff)
downloadintltool-c4150e875a0531fe2ff5de4f18c53d68088cc211.tar.gz
First shot at adding extraction support for Qt Designer .ui files
-rw-r--r--intltool-extract.in31
-rw-r--r--tests/cases/extract-qtdesigner.ui210
-rw-r--r--tests/results/extract-qtdesigner.ui.h13
3 files changed, 253 insertions, 1 deletions
diff --git a/intltool-extract.in b/intltool-extract.in
index 5afc292..33bb447 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,34 @@ sub type_quotedxml {
}
}
+sub type_qtdesigner {
+ ### For translatable Qt Designer XML files ###
+ # From http://qt-project.org/doc/designer-ui-file-format.html and
+ # http://qt-project.org/doc/linguist-ts-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
+
+ # $1 $2 $3 $4
+ while ($input =~ /<string(?:\s+[^>]*notr\s*=\s*"([^"]*)")?(?:\s+[^>]*\bcomment\b\s*=\s*"([^"]*)")?(?:\s+[^>]*extracomment\s*=\s*"([^"]*)")?[^>]*>([^<]+)<\/string>/sg) {
+ if (defined($1)){
+ next;
+ }
+ my $message = entity_decode($4);
+ if (defined($2)) {
+ $message = entity_decode($2) . "\004" . $message;
+ }
+ add_message($message);
+ if (defined($3)) {
+ $comments{$message} = entity_decode($3) ;
+ }
+ }
+}
+
sub type_glade {
### For translatable Glade XML files ###
diff --git a/tests/cases/extract-qtdesigner.ui b/tests/cases/extract-qtdesigner.ui
new file mode 100644
index 0000000..043e006
--- /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">Tab 1</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="This is a comment (extracomment)">Intltool extract text</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="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="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/extract-qtdesigner.ui.h b/tests/results/extract-qtdesigner.ui.h
new file mode 100644
index 0000000..6f5bed8
--- /dev/null
+++ b/tests/results/extract-qtdesigner.ui.h
@@ -0,0 +1,13 @@
+char *s = N_("Form");
+/* This is a comment (extracomment) */
+char *s = N_("Intltool extract text");
+char *s = N_("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+ "<html><head><meta name=\"qrichtext\" content=\"1\" /><title>HTML document extraction test</title><style type=\"text/css\">\n"
+ "p, li { white-space: pre-wrap; }\n"
+ "</style></head><body style=\" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
+ "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Once upon a time, in a galaxy far, far away... </p></body></html>");
+/* 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");
+/* Authentication is required to perform this action */
+char *s = N_("Require authentication");