diff options
-rw-r--r-- | doc/intltool-extract.8 | 2 | ||||
-rw-r--r-- | intltool-extract.in | 74 | ||||
-rw-r--r-- | tests/cases/Makefile.am | 2 | ||||
-rw-r--r-- | tests/cases/extract-qtdesigner.ui | 210 | ||||
-rw-r--r-- | tests/results/Makefile.am | 1 | ||||
-rw-r--r-- | tests/results/extract-qtdesigner.ui.h | 13 | ||||
-rwxr-xr-x | tests/selftest.pl.in | 5 |
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><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><title>HTML document extraction test</title><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<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></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_("<!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>"); +/* 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"); |