summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanilo Segan <danilo@canonical.com>2011-10-08 21:26:12 +0200
committerDanilo Segan <danilo@canonical.com>2011-10-08 21:26:12 +0200
commit2020eabd1f2ec51129b093119e56103b9c2073ec (patch)
treea2169e789cf1b75b3db562ad359160af62acdfa7
parentf52b713ee389b7335a414d9e2decf294d603379e (diff)
parentfe25ba8c53f6625d0c73ae90a92dc3f491442d44 (diff)
downloadintltool-2020eabd1f2ec51129b093119e56103b9c2073ec.tar.gz
Add support for GSettings, based on Ryan 'desrt' Lortie's code. Well, better late than never, right? Ok, very late. Fixes #580526.
-rw-r--r--doc/intltool-extract.82
-rw-r--r--intltool-extract.in57
-rw-r--r--intltool-update.in5
-rw-r--r--tests/cases/Makefile.am2
-rw-r--r--tests/cases/gsettings.gschema.xml17
-rw-r--r--tests/results/Makefile.am1
-rw-r--r--tests/results/gsettings.gschema.xml.h7
-rwxr-xr-xtests/selftest.pl.in5
8 files changed, 91 insertions, 5 deletions
diff --git a/doc/intltool-extract.8 b/doc/intltool-extract.8
index bdf3733..f0a2998 100644
--- a/doc/intltool-extract.8
+++ b/doc/intltool-extract.8
@@ -39,6 +39,8 @@ Specify the type of source file. Currently supported types are:
.br
"gettext/glade" (.glade, .glade2)
.br
+"gettext/gsettings" (.gschema.xml)
+.br
"gettext/ini" (Generic INI file)
.br
"gettext/keys" (.keys)
diff --git a/intltool-extract.in b/intltool-extract.in
index 1645fac..94594eb 100644
--- a/intltool-extract.in
+++ b/intltool-extract.in
@@ -164,8 +164,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 +219,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 +627,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:
@@ -638,7 +638,7 @@ sub readXml
sub type_schemas {
### For schemas XML files ###
-
+
# FIXME: We should handle escaped < (less than)
while ($input =~ /
<locale\ name="C">\s*
@@ -659,6 +659,53 @@ sub type_schemas {
}
}
+# Parse the tree as returned by readXml() for gschema.xml files.
+sub traverse_gsettings {
+ my $nodename = shift;
+ my $content = shift;
+ my $comment = shift || 0;
+ my @list = @{ $content };
+ my $attrs_ref = shift @list;
+ my %attrs = %{ $attrs_ref };
+ if (($nodename eq 'default' and $attrs{'l10n'}) or
+ ($nodename eq 'summary') or ($nodename eq 'description')) {
+ my $message = getXMLstring($content);
+ my $context = $attrs{'context'};
+ $context =~ s/^["'](.*)["']/$1/ if $context;
+ $message = $context . "\004" . $message if $context;
+ add_message($message);
+ $comments{$message} = $comment if $comment;
+ } else {
+ my $index = 0;
+ my $comment;
+ while (scalar(@list) > 1) {
+ my $type = shift @list;
+ my $content = shift @list;
+ if (!$type || "$type" eq "1") {
+ if ($type == 1) {
+ $comment = $content;
+ }
+ next;
+ } else {
+ traverse_gsettings($type, $content, $comment);
+ $comment = 0;
+ }
+ }
+ }
+}
+
+sub type_gsettings {
+ 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_gsettings($node, $content);
+}
+
sub type_rfc822deb {
### For rfc822-style Debian configuration files ###
@@ -923,7 +970,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..df591c6 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");