diff options
author | Danilo Segan <danilo@canonical.com> | 2011-10-08 20:08:58 +0200 |
---|---|---|
committer | Danilo Segan <danilo@canonical.com> | 2011-10-08 20:08:58 +0200 |
commit | c1b3fc2b64aaada233a5d98cf8aba8a00f11ebac (patch) | |
tree | 303030d20d0e4537b588c45804af406a51b57f77 | |
parent | f52b713ee389b7335a414d9e2decf294d603379e (diff) | |
download | intltool-c1b3fc2b64aaada233a5d98cf8aba8a00f11ebac.tar.gz |
Apply patch from Ryan with a few fixes and a test case.
-rw-r--r-- | intltool-extract.in | 64 | ||||
-rw-r--r-- | intltool-update.in | 5 | ||||
-rw-r--r-- | tests/cases/Makefile.am | 2 | ||||
-rw-r--r-- | tests/cases/gsettings.gschema.xml | 17 | ||||
-rw-r--r-- | tests/results/Makefile.am | 1 | ||||
-rw-r--r-- | tests/results/gsettings.gschema.xml.h | 7 | ||||
-rwxr-xr-x | tests/selftest.pl.in | 5 |
7 files changed, 97 insertions, 4 deletions
diff --git a/intltool-extract.in b/intltool-extract.in index 1645fac..a227eb9 100644 --- a/intltool-extract.in +++ b/intltool-extract.in @@ -38,6 +38,7 @@ my $VERSION = "@VERSION@"; use strict; use File::Basename; use Getopt::Long; +use XML::Parser; ## Scalars used by the option stuff my $TYPE_ARG = "0"; @@ -164,8 +165,8 @@ XML files. Read manpage (man ${PROGRAM}) for more info. --type=TYPE Specify the file type of FILENAME. Currently supports: "gettext/glade", "gettext/ini", "gettext/keys" "gettext/rfc822deb", "gettext/schemas", - "gettext/xml", "gettext/quoted", "gettext/quotedxml", - "gettext/tlk" + "gettext/gsettings", "gettext/xml", "gettext/quoted", + "gettext/quotedxml", "gettext/tlk" -l, --local Writes output into current working directory (conflicts with --update) --update Writes output into the same directory the source file @@ -219,6 +220,7 @@ sub convert { &type_keys if $gettext_type eq "keys"; &type_xml if $gettext_type eq "xml"; &type_glade if $gettext_type eq "glade"; + &type_gsettings if $gettext_type eq "gsettings"; &type_schemas if $gettext_type eq "schemas"; &type_rfc822deb if $gettext_type eq "rfc822deb"; &type_quoted if $gettext_type eq "quoted"; @@ -626,7 +628,6 @@ sub readXml ## differences end here from intltool-merge.in.in my $tree = $xp->parse($xmldoc); - #print_var($tree); # <foo><!-- comment --><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo> # would be: @@ -659,6 +660,61 @@ sub type_schemas { } } + my $content; + my $comment; + my %attrs; + +sub type_gsettings { + + + sub element_start { + shift; shift; + $content = ''; + %attrs = @_; + } + + sub cleanup { + s/^\s+//; + s/\s+$//; + s/\s+/ /g; + return $_; + } + + sub element_end { + my ($expat, $element) = @_; + + if (($element eq 'default' and $attrs{'l10n'}) or + ($element eq 'summary') or ($element eq 'description')) { + $content = (join "\n\n", map cleanup, split/\n\n/, $content); + $content = $attrs{'context'} . "\004" . $content + if $attrs{'context'}; + add_message(entity_decode($content)); + $comments{entity_decode($content)} = $comment + if (defined($comment)); + } + undef $comment; + } + + sub comment { + my ($expat, $data) = @_; + $comment = $data; + } + + sub char { + my ($expat, $data) = @_; + $content = $content . $data; + } + + #use Data::Dumper; + #print Dumper readXml($input); print "\n"; + + my $parser = new XML::Parser (Handlers => {Start => \&element_start, + End => \&element_end, + Comment => \&comment, + Char => \&char}); + $parser->parse($input); +} + sub type_rfc822deb { ### For rfc822-style Debian configuration files ### @@ -923,7 +979,7 @@ sub msg_write { if defined $comments{$message}; print OUT "/* xgettext:no-c-format */\n" if $message =~ /%/; - if ($message =~ /(.*)\004(.*)/) { + if ($message =~ /(.*)\004(.*)/s) { $context = $1; $message = $2; } diff --git a/intltool-update.in b/intltool-update.in index 58add1d..4bcf2c0 100644 --- a/intltool-update.in +++ b/intltool-update.in @@ -69,6 +69,7 @@ my $xml_support = "server(?:\\.in)+|". # Bonobo specific "sheet(?:\\.in)+|". # ? "schemas(?:\\.in)+|". # GConf specific +"gschema.xml|". # GLib schema (ie: GSettings) specific "pong(?:\\.in)+|". # DEPRECATED: PONG is not used [by GNOME] any longer. "kbd(?:\\.in)+|". # GOK specific. "policy(?:\\.in)+"; # PolicyKit files @@ -240,6 +241,10 @@ sub POFile_DetermineType ($) { $gettext_type=$1; } + elsif ($type =~ /gschema.xml$/) + { + $gettext_type="gsettings"; + } elsif ($type =~ /schemas(\.in)+$/) { $gettext_type="schemas"; diff --git a/tests/cases/Makefile.am b/tests/cases/Makefile.am index 8636eac..637e190 100644 --- a/tests/cases/Makefile.am +++ b/tests/cases/Makefile.am @@ -19,6 +19,7 @@ EXTRA_DIST = \ fr.po \ fr_BE.po \ fr_FR.po \ + gsettings.gschema.xml \ iso88591text.xml.in \ merge-cdata.xml.in \ merge-deepattr.xml.in \ @@ -57,6 +58,7 @@ CLEANFILES = \ extract14.xml.in.h \ extract9.xml \ extract9.xml.in.h \ + gsettings.gschema.xml.h \ iso88591text.xml.in.h \ merge-cdata.xml \ merge-deepattr.xml \ diff --git a/tests/cases/gsettings.gschema.xml b/tests/cases/gsettings.gschema.xml new file mode 100644 index 0000000..f3ad749 --- /dev/null +++ b/tests/cases/gsettings.gschema.xml @@ -0,0 +1,17 @@ +<!-- This is an example gsettings schema file. --> +<schemalist> + <schema id="org.gnome.font-rendering" path="/desktop/gnome/font_rendering/"> + <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> + </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> + </key> + </schema> +</schemalist> diff --git a/tests/results/Makefile.am b/tests/results/Makefile.am index 40a2e69..4366c6b 100644 --- a/tests/results/Makefile.am +++ b/tests/results/Makefile.am @@ -17,6 +17,7 @@ EXTRA_DIST = \ extract12.xml.in.h \ extract14.xml.in.h \ extract-gtkbuilder.ui.h \ + gsettings.gschema.xml.h \ iso88591text.xml.in.h \ merge-cdata.xml \ merge-deepattr.xml \ diff --git a/tests/results/gsettings.gschema.xml.h b/tests/results/gsettings.gschema.xml.h new file mode 100644 index 0000000..bbd4138 --- /dev/null +++ b/tests/results/gsettings.gschema.xml.h @@ -0,0 +1,7 @@ +char *s = C_("Dots Per Inch", "DPI"); +char *s = N_("The resolution used for converting font sizes to pixel sizes, in dots per inch."); +/* 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?"); diff --git a/tests/selftest.pl.in b/tests/selftest.pl.in index b016a18..e27d965 100755 --- a/tests/selftest.pl.in +++ b/tests/selftest.pl.in @@ -284,6 +284,11 @@ $case = "extract-gtkbuilder.ui"; system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1; check_extract_result($case); +print "38. Extract messages from an GSettings gschema XML file: "; +$case = "gsettings.gschema.xml"; +system("$INTLTOOL_EXTRACT --type=gettext/gsettings --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"); |