From 9c96c2f0997b45ca02b456897088f66ae068c5d1 Mon Sep 17 00:00:00 2001 From: Danilo Segan Date: Fri, 27 Jan 2012 18:31:44 +0100 Subject: Strip beginning and ending whitespace and preserve paragraphs for gsettings. Fix submitted by Ryan Lortie. --- intltool-extract.in | 22 ++++++++++++++++++- tests/cases/gsettings.gschema.xml | 41 +++++++++++++++++++++++++++++++++-- tests/results/gsettings.gschema.xml.h | 9 ++++++++ 3 files changed, 69 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 we strip leading and trailing whitespace but + # preserve (possibly quoted) whitespace within + $message =~ s/^\s+//; + $message =~ s/\s+$//; + } else { + # for and , 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..c4d7dcd 100644 --- a/tests/cases/gsettings.gschema.xml +++ b/tests/cases/gsettings.gschema.xml @@ -4,14 +4,51 @@ 96 DPI - The resolution used for converting font sizes to pixel sizes, in dots per inch. + + The resolution used for converting font sizes to pixel sizes, in + dots per inch. + + + + + 'space preserved properly' + + + + 0 + + This is a complicated key. + + + 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. + 24 Time format - How many hours can you tell apart? + + How many hours can you tell apart? + + + + 0 + + This is a key with multiple newlines. + + + Paragraph one. + + + + Paragraph two. There was never anyone who + tried to make sense out of this. + 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."); -- cgit v1.2.1 From 00384650d502343ba00b4727675ca237681c130d Mon Sep 17 00:00:00 2001 From: Danilo Segan Date: Fri, 27 Jan 2012 18:35:02 +0100 Subject: Make the spacing in test five lines to better test for double-newlines. --- tests/cases/gsettings.gschema.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cases/gsettings.gschema.xml b/tests/cases/gsettings.gschema.xml index c4d7dcd..ade9321 100644 --- a/tests/cases/gsettings.gschema.xml +++ b/tests/cases/gsettings.gschema.xml @@ -46,6 +46,7 @@ + Paragraph two. There was never anyone who tried to make sense out of this. -- cgit v1.2.1