summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanilo Segan <danilo@canonical.com>2012-01-27 18:40:40 +0100
committerDanilo Segan <danilo@canonical.com>2012-01-27 18:40:40 +0100
commitf723f40a9513a1baa922d96ddd0ac038c09f205b (patch)
treed7fa1f7d49c9159b078915361cd3e3ce181e160c
parentcb5885810da54b455bd1bfbed7e964d5db7f676a (diff)
parent00384650d502343ba00b4727675ca237681c130d (diff)
downloadintltool-f723f40a9513a1baa922d96ddd0ac038c09f205b.tar.gz
Bug #922685: Keep and normalize paragraphs in gsettings extraction. Strip starting/ending whitespace. Patch by Ryan Lortie.
-rw-r--r--intltool-extract.in22
-rw-r--r--tests/cases/gsettings.gschema.xml42
-rw-r--r--tests/results/gsettings.gschema.xml.h9
3 files changed, 70 insertions, 3 deletions
diff --git a/intltool-extract.in b/intltool-extract.in
index 94594eb..c48a9ec 100644
--- a/intltool-extract.in
+++ b/intltool-extract.in
@@ -661,6 +661,13 @@ sub type_schemas {
# Parse the tree as returned by readXml() for gschema.xml files.
sub traverse_gsettings {
+ sub cleanup {
+ s/^\s+//;
+ s/\s+$//;
+ s/\s+/ /g;
+ return $_;
+ }
+
my $nodename = shift;
my $content = shift;
my $comment = shift || 0;
@@ -669,7 +676,20 @@ sub traverse_gsettings {
my %attrs = %{ $attrs_ref };
if (($nodename eq 'default' and $attrs{'l10n'}) or
($nodename eq 'summary') or ($nodename eq 'description')) {
- my $message = getXMLstring($content);
+ # preserve whitespace. deal with it ourselves, below.
+ my $message = getXMLstring($content, 1);
+
+ if ($nodename eq 'default') {
+ # for <default> we strip leading and trailing whitespace but
+ # preserve (possibly quoted) whitespace within
+ $message =~ s/^\s+//;
+ $message =~ s/\s+$//;
+ } else {
+ # for <summary> and <description>, we normalise all
+ # whitespace while preserving paragraph boundaries
+ $message = join "\n\n", map &cleanup, split/\n\n+/, $message;
+ }
+
my $context = $attrs{'context'};
$context =~ s/^["'](.*)["']/$1/ if $context;
$message = $context . "\004" . $message if $context;
diff --git a/tests/cases/gsettings.gschema.xml b/tests/cases/gsettings.gschema.xml
index f3ad749..ade9321 100644
--- a/tests/cases/gsettings.gschema.xml
+++ b/tests/cases/gsettings.gschema.xml
@@ -4,14 +4,52 @@
<key name="dpi" type="i">
<default>96</default>
<summary context="Dots Per Inch">DPI</summary>
- <description>The resolution used for converting font sizes to pixel sizes, in dots per inch.</description>
+ <description>
+ The resolution used for converting font sizes to pixel sizes, in
+ dots per inch.
+ </description>
+ </key>
+ <key name="translated-default" type="s">
+ <default l10n='messages'>
+ 'space preserved properly'
+ </default>
+ </key>
+ <key name="complicated" type="i">
+ <default>0</default>
+ <summary>
+ This is a complicated key.
+ </summary>
+ <description context='GSettings description'>
+ This key is very complicated. You should not attempt to
+ understand it.
+
+ There was this one guy who attempted to make sense of it once.
+ We don't know what happened to him.
+ </description>
</key>
<key name="clocktype" type="i">
<!-- Translators: translate to either 12 or 24 to define the default
clock format. -->
<default l10n="messages" context="clock-format">24</default>
<summary>Time format</summary>
- <description context="Time format gsettings description">How many hours can you tell apart?</description>
+ <description context="Time format gsettings description">
+ How many hours can you tell apart?
+ </description>
+ </key>
+ <key name="newline-normalization" type="i">
+ <default>0</default>
+ <summary>
+ This is a key with multiple newlines.
+ </summary>
+ <description context='GSettings description'>
+ Paragraph one.
+
+
+
+
+ Paragraph two. There was never anyone who
+ tried to make sense out of this.
+ </description>
</key>
</schema>
</schemalist>
diff --git a/tests/results/gsettings.gschema.xml.h b/tests/results/gsettings.gschema.xml.h
index bbd4138..36679a4 100644
--- a/tests/results/gsettings.gschema.xml.h
+++ b/tests/results/gsettings.gschema.xml.h
@@ -1,7 +1,16 @@
char *s = C_("Dots Per Inch", "DPI");
char *s = N_("The resolution used for converting font sizes to pixel sizes, in dots per inch.");
+char *s = N_("'space preserved properly'");
+char *s = N_("This is a complicated key.");
+char *s = C_("GSettings description", "This key is very complicated. You should not attempt to understand it.\n"
+ "\n"
+ "There was this one guy who attempted to make sense of it once. We don't know what happened to him.");
/* Translators: translate to either 12 or 24 to define the default
clock format. */
char *s = C_("clock-format", "24");
char *s = N_("Time format");
char *s = C_("Time format gsettings description", "How many hours can you tell apart?");
+char *s = N_("This is a key with multiple newlines.");
+char *s = C_("GSettings description", "Paragraph one.\n"
+ "\n"
+ "Paragraph two. There was never anyone who tried to make sense out of this.");