From: Bruno Haible Date: Sun, 29 Sep 2024 14:47:30 +0000 (+0200) Subject: Provide XML schemas for .its and .loc files. X-Git-Tag: v0.23~102 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ba96bb87e6d106cf67d01431c8586ff3486b835;p=thirdparty%2Fgettext.git Provide XML schemas for .its and .loc files. Suggested by Martin Blanchard at . * gettext-tools/src/its.xsd: New file, reverse-engineered from its.c. * gettext-tools/src/its-extensions.xsd: New file, reverse-engineered from its.c. * gettext-tools/src/locating-rules.xsd: New file, reverse-engineered from locating-rules.c. * gettext-tools/src/Makefile.am (schemadir): New variable. (schema_DATA): New variable. (EXTRA_DIST): Distribute all of schema_DATA. * gettext-tools/configure.ac: Check for xmllint, and set XMLLINT. * gettext-tools/its/Makefile.am (ITS_FILES, LOC_FILES): New variables. (dist_its_DATA): Rewrite. (check-local): New rule. * gettext-tools/doc/gettext.texi (Preparing ITS Rules): Split into two subsections. Mention which schema the files have to obey. * HACKING: Mention xmllint as maintainer prerequisite. * PACKAGING: Mention the $prefix/share/gettext/schema/ directory. * NEWS: Mention the change. --- diff --git a/HACKING b/HACKING index 6919ff23b..b29b4ab88 100644 --- a/HACKING +++ b/HACKING @@ -141,6 +141,13 @@ Additional requirements for maintainers If you are a maintainer, you will want to minimize the number of tests that are skipped. To this effect, you need to install also: + * The xmllint program + + Homepage: https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home + + Pre-built package name: + - On Debian and Debian-based systems: libxml2-utils, + - On Red Hat distributions: libxml2. + - Other: https://repology.org/project/libxml2/versions + * A C++ compiler + Homepage: https://gcc.gnu.org/ + Pre-built package name: diff --git a/NEWS b/NEWS index 3961ba2e1..88bbdde60 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ Version 0.23 - September 2024 * Programming languages support: + - XML: XML schemas for .its and .loc files are now provided. - Python: o xgettext now assumes source code for Python 3 rather than Python 2. This affects the interpretation of escape sequences in string literals. diff --git a/PACKAGING b/PACKAGING index d6df1fc46..942309c33 100644 --- a/PACKAGING +++ b/PACKAGING @@ -133,6 +133,7 @@ is according to the following file list. $prefix/share/gettext/config.rpath $prefix/share/gettext/po/* $prefix/share/gettext/projects/* + $prefix/share/gettext/schema/* $prefix/share/gettext/styles/* $prefix/share/gettext/gettext.h $prefix/share/gettext/gettext.jar diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index 4fb68a6a1..1542d9ba6 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -592,6 +592,9 @@ dnl Check whether to execute tests of the system (vendor-provided) libintl API. dnl We execute these tests if and only if we don't install our own libintl. AM_CONDITIONAL([TEST_SYSTEM_LIBINTL], [test $USE_INCLUDED_LIBINTL = no]) +dnl Checks for optional programs for the its/* tests. +AC_PATH_PROGS([XMLLINT], [xmllint], [:]) + AC_CONFIG_SUBDIRS([examples]) AC_CONFIG_FILES([Makefile], diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index 88096771f..e70b9e57b 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -487,6 +487,11 @@ Internationalizable Data Formats * AppData:: AppData - freedesktop.org application description * Preparing ITS Rules:: Preparing Rules for XML Internationalization +Preparing Rules for XML Internationalization + +* ITS Rules:: Specifying ITS Rules +* Locating Rules:: Specifying where to find the ITS Rules + Localized Data Formats * Editable Message Catalogs:: Editable Message Catalogs @@ -10651,6 +10656,14 @@ appdata-tools, appstream, libappstream-glib-dev @subsection Preparing Rules for XML Internationalization @cindex preparing rules for XML translation +@menu +* ITS Rules:: Specifying ITS Rules +* Locating Rules:: Specifying where to find the ITS Rules +@end menu + +@node ITS Rules +@subsubsection Specifying ITS Rules + Marking translatable strings in an XML file is done through a separate "rule" file, making use of the Internationalization Tag Set standard (ITS, @uref{https://www.w3.org/TR/its20/}). The currently supported ITS @@ -10751,9 +10764,16 @@ second ("A non-translatable string"), the following ITS rules can be used: @end example -@samp{xgettext} needs another file called "locating rule" to associate +ITS rules files must have the @file{.its} file extension and obey +the XML schema encoded by +@code{its.xsd} and its auxiliary schema @code{its-extensions.xsd}. + +@node Locating Rules +@subsubsection Specifying where to find the ITS Rules + +@samp{xgettext} needs another file called "locating rules" to associate an ITS rule with an XML file. If the above ITS file is saved as -@file{messages.its}, the locating rule would look like: +@file{messages.its}, the locating rules file would look like: @example @@ -10779,18 +10799,19 @@ file. The first rule matches any file with the @file{.xml} file extension, but it only applies to XML files whose root element is @samp{}. -The second rule indicates that the same ITS rule file are also +The second rule indicates that the same ITS rules file are also applicable to any file with the @file{.msg} file extension. The optional @code{name} attribute of @code{locatingRule} allows to choose rules by name, typically with @code{xgettext}'s @code{-L} option. -The associated ITS rule file is indicated by the @code{target} attribute +The associated ITS rules file is indicated by the @code{target} attribute of @code{locatingRule} or @code{documentRule}. If it is specified in a @code{documentRule} element, the parent @code{locatingRule} shouldn't have the @code{target} attribute. -Locating rule files must have the @file{.loc} file extension. Both ITS -rule files and locating rule files must be installed in the +Locating rules files must have the @file{.loc} file extension and obey +the XML schema encoded by @code{locating-rules.xsd}. +Both ITS rules files and locating rules files must be installed in the @file{$prefix/share/gettext/its} directory. Once those files are properly installed, @code{xgettext} can extract translatable strings from the matching XML files. diff --git a/gettext-tools/its/Makefile.am b/gettext-tools/its/Makefile.am index b33081efb..7c50961b9 100644 --- a/gettext-tools/its/Makefile.am +++ b/gettext-tools/its/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for the gettext-tools/its subdirectory of GNU gettext -## Copyright (C) 2015, 2017 Free Software Foundation, Inc. +## Copyright (C) 2015-2024 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -20,5 +20,28 @@ AUTOMAKE_OPTIONS = 1.2 gnits pkgdatadir = $(datadir)/gettext itsdir = $(pkgdatadir)$(PACKAGE_SUFFIX)/its -dist_its_DATA = glade.loc glade1.its glade2.its gtkbuilder.its \ -gsettings.loc gsettings.its metainfo.loc metainfo.its + +ITS_FILES = \ + glade1.its glade2.its gtkbuilder.its \ + gsettings.its \ + metainfo.its + +LOC_FILES = \ + glade.loc \ + gsettings.loc \ + metainfo.loc + +dist_its_DATA = $(ITS_FILES) $(LOC_FILES) + +# Checks the XML files against their schemas. +check-local: + @for file in $(ITS_FILES); do \ + echo "Checking $$file..."; \ + echo "$(XMLLINT) --noout --schema $(top_srcdir)/src/its.xsd $(srcdir)/$$file"; \ + $(XMLLINT) --noout --schema $(top_srcdir)/src/its.xsd $(srcdir)/$$file || exit 1; \ + done + @for file in $(LOC_FILES); do \ + echo "Checking $$file..."; \ + echo "$(XMLLINT) --noout --schema $(top_srcdir)/src/locating-rules.xsd $(srcdir)/$$file"; \ + $(XMLLINT) --noout --schema $(top_srcdir)/src/locating-rules.xsd $(srcdir)/$$file || exit 1; \ + done diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index 2cdedfb25..d99da82ab 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -97,6 +97,7 @@ EXTRA_DIST += FILES project-id jardir = $(datadir)/gettext pkgdatadir = $(datadir)/gettext projectsdir = $(pkgdatadir)/projects +schemadir = $(pkgdatadir)/schema pkglibdir = $(libdir)/gettext pkglibexecdir = $(libexecdir)/gettext @@ -761,6 +762,14 @@ uninstall-tcl: $(RM) $(DESTDIR)$(pkgdatadir)/msgunfmt.tcl +# Special rules for XML schemas. + +schema_DATA = \ + its.xsd its-extensions.xsd \ + locating-rules.xsd +EXTRA_DIST += $(schema_DATA) + + # Support for relocatability. RELOCATABLE_LIBRARY_PATH = $(libdir) RELOCATABLE_SRC_DIR = $(top_srcdir)/gnulib-lib diff --git a/gettext-tools/src/its-extensions.xsd b/gettext-tools/src/its-extensions.xsd new file mode 100644 index 000000000..b85c3cbe2 --- /dev/null +++ b/gettext-tools/src/its-extensions.xsd @@ -0,0 +1,54 @@ + + + + + XML schema extensions for *.its files, as understood by GNU gettext. + +Copyright (C) 2015-2024 Free Software Foundation, Inc. + +This file is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +This file is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +Written by Bruno Haible <bruno@clisp.org>, 2024. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gettext-tools/src/its.xsd b/gettext-tools/src/its.xsd new file mode 100644 index 000000000..a0bfe58ef --- /dev/null +++ b/gettext-tools/src/its.xsd @@ -0,0 +1,89 @@ + + + + + XML schema of *.its files, as understood by GNU gettext. + +Copyright (C) 2015-2024 Free Software Foundation, Inc. + +This file is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +This file is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +Written by Bruno Haible <bruno@clisp.org>, 2024. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Note: An instance should not have both the 'locNotePointer' attribute and a 'locNote' child at the same time. + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gettext-tools/src/locating-rules.xsd b/gettext-tools/src/locating-rules.xsd new file mode 100644 index 000000000..3bb86fd13 --- /dev/null +++ b/gettext-tools/src/locating-rules.xsd @@ -0,0 +1,88 @@ + + + + + XML schema of *.loc files, as understood by GNU gettext. + +Copyright (C) 2015-2024 Free Software Foundation, Inc. + +This file is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation, either version 3 of the License, +or (at your option) any later version. + +This file is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. + +Written by Bruno Haible <bruno@clisp.org>, 2024. + + + + + + + + + + + Example: +<locatingRules> + <locatingRule name="Glade" pattern="*.glade"> + <documentRule localName="GTK-Interface" target="glade1.its"/> + <documentRule localName="glade-interface" target="glade2.its"/> + <documentRule localName="interface" target="gtkbuilder.its"/> + </locatingRule> + <locatingRule name="Glade" pattern="*.glade2"> + <documentRule localName="glade-interface" target="glade2.its"/> + </locatingRule> + <locatingRule name="Glade" pattern="*.ui"> + <documentRule localName="interface" target="gtkbuilder.its"/> + </locatingRule> +</locatingRules> + + + + + + + + + + + + Example: +&lt;locatingRule name=&quot;Glade&quot; pattern=&quot;*.glade&quot;&gt; + &lt;documentRule localName=&quot;GTK-Interface&quot; target=&quot;glade1.its&quot;/&gt; + &lt;documentRule localName=&quot;glade-interface&quot; target=&quot;glade2.its&quot;/&gt; + &lt;documentRule localName=&quot;interface&quot; target=&quot;gtkbuilder.its&quot;/&gt; +&lt;/locatingRule&gt; + +Note: An instance should not have both the 'target' attribute and a 'documentRule' child at the same time. + + + + + + + + + + + + + Example: +<documentRule localName="GTK-Interface" target="glade1.its"/> + + + + + + +