diff options
author | David Planella <david.planella@ubuntu.com> | 2013-01-28 00:45:01 +0100 |
---|---|---|
committer | David Planella <david.planella@ubuntu.com> | 2013-01-28 00:45:01 +0100 |
commit | bdc3acd8ac486617245d9bb4de7d5f4e801e4ebe (patch) | |
tree | 4d34a5f1eb2c50884a7cf43eea2adf21ab38de25 | |
parent | 9c69b7fc7966f92a1da20e8a18abcf1ebff6c97e (diff) | |
download | intltool-bdc3acd8ac486617245d9bb4de7d5f4e801e4ebe.tar.gz |
Cleaned up qtdesigner code, added comments, updated test case and results
-rw-r--r-- | intltool-extract.in | 33 | ||||
-rw-r--r-- | tests/cases/extract-qtdesigner.ui | 8 | ||||
-rw-r--r-- | tests/results/extract-qtdesigner.ui.h | 8 |
3 files changed, 35 insertions, 14 deletions
diff --git a/intltool-extract.in b/intltool-extract.in index 33bb447..610b5e3 100644 --- a/intltool-extract.in +++ b/intltool-extract.in @@ -840,19 +840,40 @@ sub type_qtdesigner { # 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> + + # 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; + } - # $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; - } + # 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) ; + $comments{$message} = entity_decode($3); } } } diff --git a/tests/cases/extract-qtdesigner.ui b/tests/cases/extract-qtdesigner.ui index 043e006..7c16560 100644 --- a/tests/cases/extract-qtdesigner.ui +++ b/tests/cases/extract-qtdesigner.ui @@ -33,7 +33,7 @@ </property> <widget class="QWidget" name="tabWelcome"> <attribute name="title"> - <string notr="true">Tab 1</string> + <string notr="true">Do not translate this</string> </attribute> <layout class="QHBoxLayout" name="horizontalLayout_5"> <property name="spacing"> @@ -91,7 +91,7 @@ </font> </property> <property name="text"> - <string extracomment="This is a comment (extracomment)">Intltool extract text</string> + <string extracomment="TRANSLATORS: this is the main title of the authentication dialog">This is a translatable title</string> </property> </widget> </widget> @@ -156,7 +156,7 @@ p, li { white-space: pre-wrap; } </font> </property> <property name="text"> - <string comment="Button" extracomment="Refers to the action of accepting something">Ok</string> + <string comment="Button" extracomment="TRANSLATORS: refers to the action of accepting something">Ok</string> </property> </widget> <widget class="QCheckBox" name="checkBox"> @@ -192,7 +192,7 @@ p, li { white-space: pre-wrap; } </font> </property> <property name="text"> - <string extracomment="Authentication is required to perform this action">Require authentication</string> + <string extracomment="TRANSLATORS: authentication is required to perform this action">Require authentication</string> </property> </widget> </widget> diff --git a/tests/results/extract-qtdesigner.ui.h b/tests/results/extract-qtdesigner.ui.h index 6f5bed8..a9b997c 100644 --- a/tests/results/extract-qtdesigner.ui.h +++ b/tests/results/extract-qtdesigner.ui.h @@ -1,13 +1,13 @@ char *s = N_("Form"); -/* This is a comment (extracomment) */ -char *s = N_("Intltool extract text"); +/* 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>"); -/* Refers to the action of accepting something */ +/* 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"); -/* Authentication is required to perform this action */ +/* TRANSLATORS: authentication is required to perform this action */ char *s = N_("Require authentication"); |