diff options
author | Shaun McCance <shaunm@src.gnome.org> | 2004-10-21 06:25:27 +0000 |
---|---|---|
committer | Shaun McCance <shaunm@src.gnome.org> | 2004-10-21 06:25:27 +0000 |
commit | 523c518bf7ca77b29c76ebc82ac8877005799265 (patch) | |
tree | 8a3a94cf5aed5f4365227223f55b6d0ca16b7783 | |
parent | ae3d9105e97e081d0dc3842f6e9276d17d760ebf (diff) | |
download | gnome-doc-utils-523c518bf7ca77b29c76ebc82ac8877005799265.tar.gz |
- Stub for documentation for translators
* doc/xslt/Makefile.am:
* doc/xslt/C/gnome-doc-xslt.xml:
* doc/xslt/C/translating.xml:
- Stub for documentation for translators
* xslt/docbook/common/db-format.xml.in:
* xslt/gettext/format2xsl.xsl:
* xslt/gettext/gettext.xsl:
* xslt/gettext/l10n.xml.in:
- Massively improved translation mechanisms, almost finished
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | doc/xslt/C/gnome-doc-xslt.xml | 3 | ||||
-rw-r--r-- | doc/xslt/C/translating.xml | 36 | ||||
-rw-r--r-- | doc/xslt/Makefile.am | 2 | ||||
-rw-r--r-- | xslt/docbook/common/db-format.xml.in | 68 | ||||
-rw-r--r-- | xslt/gettext/format2xsl.xsl | 214 | ||||
-rw-r--r-- | xslt/gettext/gettext.xsl | 614 | ||||
-rw-r--r-- | xslt/gettext/l10n.xml.in | 94 |
8 files changed, 667 insertions, 377 deletions
@@ -1,3 +1,16 @@ +2004-10-21 Shaun McCance <shaunm@gnome.org> + + * doc/xslt/Makefile.am: + * doc/xslt/C/gnome-doc-xslt.xml: + * doc/xslt/C/translating.xml: + - Stub for documentation for translators + + * xslt/docbook/common/db-format.xml.in: + * xslt/gettext/format2xsl.xsl: + * xslt/gettext/gettext.xsl: + * xslt/gettext/l10n.xml.in: + - Massively improved translation mechanisms, almost finished + 2004-10-20 Shaun McCance <shaunm@gnome.org> * xslt/docbook/html/db2html-admon.xsl: diff --git a/doc/xslt/C/gnome-doc-xslt.xml b/doc/xslt/C/gnome-doc-xslt.xml index ffb396e..0aafb43 100644 --- a/doc/xslt/C/gnome-doc-xslt.xml +++ b/doc/xslt/C/gnome-doc-xslt.xml @@ -5,7 +5,7 @@ <article id="index" lang="en"> <articleinfo> - <title>GNOME XSLT Manual</title> + <title>GNOME Documentation XSLT Manual</title> <copyright> <year>2004</year> <holder>Shaun McCance</holder> @@ -47,5 +47,6 @@ <include href="rngdoc.xml" xmlns="http://www.w3.org/2001/XInclude"/> <include href="xsldoc.xml" xmlns="http://www.w3.org/2001/XInclude"/> <include href="gettext.xml" xmlns="http://www.w3.org/2001/XInclude"/> + <include href="translating.xml" xmlns="http://www.w3.org/2001/XInclude"/> </article> diff --git a/doc/xslt/C/translating.xml b/doc/xslt/C/translating.xml new file mode 100644 index 0000000..d7e9695 --- /dev/null +++ b/doc/xslt/C/translating.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<section id="translating"> + <title>Translating the Stylesheets</title> + <para>The GNOME documentation stylesheets use two different mechanisms for + internationalization. The simpler method is provided by + <filename>gettext.xsl</filename>. This method reads in translated strings + from a simple <filename>l10n.xml</filename> file, which is easily managed + using PO files and <command>intltool</command>. The other method is + provided by <filename>format2xsl.xsl</filename>. This method converts + special format files to XSLT stylesheets at build time. It is considerably + more flexible than the <filename>gettext</filename> method, as it allows + translators programmer-level control over the formatted output.</para> + + <para>Generally, the <filename>gettext</filename> method is used only + for simple string lookups that require no special formatting. However, + since it tends to have better performance than the + <filename>format2xsl</filename> method, it is preferred whenever + possible. If you are providing translations and find that a string marked + for translation is insufficient for your locale, you should request to have + that translation reworked using <filename>format2xsl</filename>. Document + processing is a much more difficult task for internationalization than most + simple application translations in GNOME. The maintainers don't know all + the nuances of document processing in every language, so the only way we + can improve the internationalization support is with the help of the + translators.</para> + + <section id="translating-gettext"> + <title>The <filename>gettext</filename> Method</title> + <para/> + </section> + + <section id="translating-format2xsl"> + <title>The <filename>format2xsl</filename> Method</title> + <para/> + </section> +</section> diff --git a/doc/xslt/Makefile.am b/doc/xslt/Makefile.am index 305c78a..cd4d0cd 100644 --- a/doc/xslt/Makefile.am +++ b/doc/xslt/Makefile.am @@ -3,7 +3,7 @@ include $(top_srcdir)/bootstrap.make dist-hook: doc-dist-hook DOC_MODULE = gnome-doc-xslt -DOC_INCLUDES = legal.xml +DOC_INCLUDES = legal.xml translating.xml DOC_LINGUAS = sr diff --git a/xslt/docbook/common/db-format.xml.in b/xslt/docbook/common/db-format.xml.in index 186c587..c1101b3 100644 --- a/xslt/docbook/common/db-format.xml.in +++ b/xslt/docbook/common/db-format.xml.in @@ -43,6 +43,74 @@ </xsl:template> +<!-- == format.date ======================================================== --> + +<template xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>format.date</name> + <description> + Format a date + </description> + <parameter> + <node>year</node> + <description> + The year in the Gregorian calendar + </description> + </parameter> + <parameter> + <name>month</name> + <description> + The number of the month + </description> + </parameter> + <parameter> + <name>day</name> + <description> + The number of the day in the month + </description> + </parameter> +</template> + +<xsl:template name="format.date"> + <xsl:param name="year"/> + <xsl:param name="month"/> + <xsl:param name="day"/> + <msg:msg id="format.date"> + <!-- FIXME --> + <_msg:msgstr>format.date</_msg:msgstr> + <msg:msgstr xml:lang="C"> + <xsl:template> + <xsl:choose> + <xsl:when test="$month = 1"><xsl:text>January </xsl:text></xsl:when> + <xsl:when test="$month = 2"><xsl:text>February </xsl:text></xsl:when> + <xsl:when test="$month = 3"><xsl:text>March </xsl:text></xsl:when> + <xsl:when test="$month = 4"><xsl:text>April </xsl:text></xsl:when> + <xsl:when test="$month = 5"><xsl:text>May </xsl:text></xsl:when> + <xsl:when test="$month = 6"><xsl:text>June </xsl:text></xsl:when> + <xsl:when test="$month = 7"><xsl:text>July </xsl:text></xsl:when> + <xsl:when test="$month = 8"><xsl:text>August </xsl:text></xsl:when> + <xsl:when test="$month = 9"><xsl:text>September </xsl:text></xsl:when> + <xsl:when test="$month = 10"><xsl:text>October </xsl:text></xsl:when> + <xsl:when test="$month = 11"><xsl:text>November </xsl:text></xsl:when> + <xsl:when test="$month = 12"><xsl:text>December </xsl:text></xsl:when> + </xsl:choose> + <xsl:value-of select="$day"/> + <xsl:text>, </xsl:text> + <xsl:value-of select="$year"/> + </xsl:template> + </msg:msgstr> + </msg:msg> + <msg:arg name="year"> + <xsl:value-of select="$year"/> + </msg:arg> + <msg:arg name="month"> + <xsl:value-of select="$month"/> + </msg:arg> + <msg:arg name="day"> + <xsl:value-of select="$day"/> + </msg:arg> +</xsl:template> + + <!-- == format.quote.outer ================================================= --> <template xmlns="http://www.gnome.org/~shaunm/xsldoc"> diff --git a/xslt/gettext/format2xsl.xsl b/xslt/gettext/format2xsl.xsl index 15456d5..17da620 100644 --- a/xslt/gettext/format2xsl.xsl +++ b/xslt/gettext/format2xsl.xsl @@ -9,6 +9,8 @@ <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/> +<xsl:include href="gettext.xsl"/> + <xsl:output method="xml" encoding="UTF-8"/> <!-- == format2xsl == --> @@ -116,6 +118,9 @@ <xsl:param name="template"/> <xsl:param name="lang"/> <xsl:choose> + <xsl:when test="xsl:template"> + <xsl:apply-templates select="xsl:template/node()"/> + </xsl:when> <xsl:when test="msg:msgstr[@role]"> <xslt:choose> <xsl:for-each select="msg:msgstr[@role]"> @@ -188,83 +193,24 @@ <xsl:sort select="contains(@xml:lang, '_')" order="descending"/> <xsl:sort select="string-length(@xml:lang)" order="descending"/> <xsl:variable name="lang_lang"> - <xsl:choose> - <xsl:when test="contains(@xml:lang, '_')"> - <xsl:value-of select="substring-before(@xml:lang, '_')"/> - </xsl:when> - <xsl:when test="contains(@xml:lang, '@')"> - <xsl:value-of select="substring-before(@xml:lang, '@')"/> - </xsl:when> - <xsl:when test="contains(@xml:lang, '.')"> - <xsl:value-of select="substring-before(@xml:lang, '.')"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="@xml:lang"/> - </xsl:otherwise> - </xsl:choose> - </xsl:variable> - <xsl:variable name="lang_sans_lang"> - <xsl:value-of select="substring-after(@xml:lang, $lang_lang)"/> + <xsl:call-template name="gettext.get.language"> + <xsl:with-param name="lang" select="@xml:lang"/> + </xsl:call-template> </xsl:variable> <xsl:variable name="lang_region"> - <xsl:if test="starts-with($lang_sans_lang, '_')"> - <xsl:choose> - <xsl:when test="contains($lang_sans_lang, '@')"> - <xsl:value-of select="substring-after( - substring-before($lang_sans_lang, '@'), - '_')"/> - </xsl:when> - <xsl:when test="contains($lang_sans_lang, '.')"> - <xsl:value-of select="substring-after( - substring-before($lang_sans_lang, '.'), - '_')"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="substring-after($lang_sans_lang, '_')"/> - </xsl:otherwise> - </xsl:choose> - </xsl:if> - </xsl:variable> - <xsl:variable name="lang_sans_region"> - <xsl:choose> - <xsl:when test="$lang_region"> - <xsl:value-of select="substring-after($lang_sans_lang, - concat('_', $lang_region))"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="$lang_sans_lang"/> - </xsl:otherwise> - </xsl:choose> + <xsl:call-template name="gettext.get.region"> + <xsl:with-param name="lang" select="@xml:lang"/> + </xsl:call-template> </xsl:variable> <xsl:variable name="lang_variant"> - <xsl:if test="starts-with($lang_sans_region, '@')"> - <xsl:choose> - <xsl:when test="contains($lang_sans_region, '.')"> - <xsl:value-of select="substring-after( - substring-before($lang_sans_region, '.'), - '@')"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="substring-after($lang_sans_region, '@')"/> - </xsl:otherwise> - </xsl:choose> - </xsl:if> - </xsl:variable> - <xsl:variable name="lang_sans_variant"> - <xsl:choose> - <xsl:when test="$lang_variant"> - <xsl:value-of select="substring-after($lang_sans_region, - concat('@', $lang_region))"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="$lang_sans_region"/> - </xsl:otherwise> - </xsl:choose> + <xsl:call-template name="gettext.get.variant"> + <xsl:with-param name="lang" select="@xml:lang"/> + </xsl:call-template> </xsl:variable> <xsl:variable name="lang_charset"> - <xsl:if test="starts-with($lang_sans_variant, '.')"> - <xsl:value-of select="substring-after($lang_sans_variant, '.')"/> - </xsl:if> + <xsl:call-template name="gettext.get.charset"> + <xsl:with-param name="lang" select="@xml:lang"/> + </xsl:call-template> </xsl:variable> <xsl:variable name="element"> <xsl:choose> @@ -289,7 +235,7 @@ <xsl:text>'</xsl:text> </xsl:if> <xsl:if test="$lang_variant != ''"> - <xsl:text> nand $lang_variant = '</xsl:text> + <xsl:text> and $lang_variant = '</xsl:text> <xsl:value-of select="$lang_variant"/> <xsl:text>'</xsl:text> </xsl:if> @@ -360,24 +306,24 @@ </xsl:copy> </xsl:template> -<!-- == xsl:apply-templates == --> -<xsl:template match="xsl:apply-templates"> - <xslt:apply-templates> +<!-- == xsl:* == --> +<xsl:template match="xsl:*"> + <xsl:copy> <xsl:for-each select="attribute::*"> <xsl:copy/> </xsl:for-each> <xsl:apply-templates/> - </xslt:apply-templates> + </xsl:copy> </xsl:template> -<!-- == xsl:call-template == --> -<xsl:template match="xsl:call-template"> - <xslt:call-template> +<!-- == xsl:apply-templates == --> +<xsl:template match="xsl:apply-templates"> + <xslt:apply-templates> <xsl:for-each select="attribute::*"> <xsl:copy/> </xsl:for-each> <xsl:apply-templates/> - </xslt:call-template> + </xslt:apply-templates> </xsl:template> <!-- == xsl:number == --> @@ -397,99 +343,30 @@ </xslt:number> </xsl:template> -<!-- == xsl:param == --> -<xsl:template match="xsl:param"> - <xslt:param name="{@name}"> - <xsl:for-each select="attribute::*"> - <xsl:copy/> - </xsl:for-each> - <xsl:apply-templates/> - </xslt:param> -</xsl:template> - <!-- == xsl:template == --> <xsl:template match="xsl:template"> <xslt:template name="{@name}"> <xsl:apply-templates select="xsl:param"/> <xslt:param name="lang" select="$node/ancestor-or-self::*[@lang][1]/@lang"/> <xslt:variable name="lang_lang"> - <xslt:choose> - <xslt:when test="contains($lang, '_')"> - <xslt:value-of select="substring-before($lang, '_')"/> - </xslt:when> - <xslt:when test="contains($lang, '@')"> - <xslt:value-of select="substring-before($lang, '@')"/> - </xslt:when> - <xslt:when test="contains($lang, '.')"> - <xslt:value-of select="substring-before($lang, '.')"/> - </xslt:when> - <xslt:otherwise> - <xslt:value-of select="$lang"/> - </xslt:otherwise> - </xslt:choose> - </xslt:variable> - <xslt:variable name="lang_sans_lang"> - <xslt:value-of select="substring-after($lang, $lang_lang)"/> + <xslt:call-template name="gettext.get.language"> + <xslt:with-param name="lang" select="$lang"/> + </xslt:call-template> </xslt:variable> <xslt:variable name="lang_region"> - <xslt:if test="starts-with($lang_sans_lang, '_')"> - <xslt:choose> - <xslt:when test="contains($lang_sans_lang, '@')"> - <xslt:value-of select="substring-after( - substring-before($lang_sans_lang, '@'), - '_')"/> - </xslt:when> - <xslt:when test="contains($lang_sans_lang, '.')"> - <xslt:value-of select="substring-after( - substring-before($lang_sans_lang, '.'), - '_')"/> - </xslt:when> - <xslt:otherwise> - <xslt:value-of select="substring-after($lang_sans_lang, '_')"/> - </xslt:otherwise> - </xslt:choose> - </xslt:if> - </xslt:variable> - <xslt:variable name="lang_sans_region"> - <xslt:choose> - <xslt:when test="$lang_region"> - <xslt:value-of select="substring-after($lang_sans_lang, - concat('_', $lang_region))"/> - </xslt:when> - <xslt:otherwise> - <xslt:value-of select="$lang_sans_lang"/> - </xslt:otherwise> - </xslt:choose> + <xslt:call-template name="gettext.get.region"> + <xslt:with-param name="lang" select="$lang"/> + </xslt:call-template> </xslt:variable> <xslt:variable name="lang_variant"> - <xslt:if test="starts-with($lang_sans_region, '@')"> - <xslt:choose> - <xslt:when test="contains($lang_sans_region, '.')"> - <xslt:value-of select="substring-after( - substring-before($lang_sans_region, '.'), - '@')"/> - </xslt:when> - <xslt:otherwise> - <xslt:value-of select="substring-after($lang_sans_region, '@')"/> - </xslt:otherwise> - </xslt:choose> - </xslt:if> - </xslt:variable> - <xslt:variable name="lang_sans_variant"> - <xslt:choose> - <xslt:when test="$lang_variant"> - <xslt:value-of select="substring-after($lang_sans_region, - concat('@', $lang_region))"/> - </xslt:when> - <xslt:otherwise> - <xslt:value-of select="$lang_sans_region"/> - </xslt:otherwise> - </xslt:choose> + <xslt:call-template name="gettext.get.variant"> + <xslt:with-param name="lang" select="$lang"/> + </xslt:call-template> </xslt:variable> <xslt:variable name="lang_charset"> - <xslt:if test="starts-with($lang_sans_variant, '.')"> - <xslt:value-of select="substring-after($lang_sans_variant, '.')"/> - </xslt:if> + <xslt:call-template name="gettext.get.charset"> + <xslt:with-param name="lang" select="$lang"/> + </xslt:call-template> </xslt:variable> <xsl:apply-templates select="msg:msg"/> </xslt:template> @@ -502,19 +379,4 @@ </xslt:stylesheet> </xsl:template> -<!-- == xsl:value-of == --> -<xsl:template match="xsl:value-of"> - <xslt:value-of select="{@select}"/> -</xsl:template> - -<!-- == xsl:with-param == --> -<xsl:template match="xsl:with-param"> - <xslt:with-param name="{@name}"> - <xsl:for-each select="attribute::*"> - <xsl:copy/> - </xsl:for-each> - <xsl:apply-templates/> - </xslt:with-param> -</xsl:template> - </xsl:stylesheet> diff --git a/xslt/gettext/gettext.xsl b/xslt/gettext/gettext.xsl index b915aa7..8980a96 100644 --- a/xslt/gettext/gettext.xsl +++ b/xslt/gettext/gettext.xsl @@ -2,174 +2,574 @@ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc="http://www.gnome.org/~shaunm/xsldoc" + xmlns:msg="http://www.gnome.org/~shaunm/gnome-doc-utils/xsl-format" exclude-result-prefixes="doc" version="1.0"> <xsl:variable name="l10n" select="document('l10n.xml')"/> -<xsl:key name="msgid" match="msg" use="msgid"/> +<xsl:key name="msgid" match="msg:msg" use="msg:msgid"/> <doc:title>Gettext</doc:title> +<!-- == gettext.locale ===================================================== --> + +<parameter xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.locale</name> + <description> + The top-level locale of the document + </description> +</parameter> + +<xsl:param name="gettext.locale"> + <xsl:choose> + <xsl:when test="/*/@xml:lang"> + <xsl:value-of select="/*/@xml:lang"/> + </xsl:when> + <xsl:when test="/*/@lang"> + <xsl:value-of select="/*/@lang"/> + </xsl:when> + </xsl:choose> +</xsl:param> + + +<!-- == gettext.language =================================================== --> + +<parameter xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.language</name> + <description> + The language part of the top-level locale of the document + </description> +</parameter> + +<xsl:param name="gettext.language"> + <xsl:choose> + <xsl:when test="contains($gettext.locale, '_')"> + <xsl:value-of select="substring-before($gettext.locale, '_')"/> + </xsl:when> + <xsl:when test="contains($gettext.locale, '@')"> + <xsl:value-of select="substring-before($gettext.locale, '@')"/> + </xsl:when> + <xsl:when test="contains($gettext.locale, '_')"> + <xsl:value-of select="substring-before($gettext.locale, '@')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$gettext.locale"/> + </xsl:otherwise> + </xsl:choose> +</xsl:param> + + +<!-- == gettext.region ===================================================== --> + +<parameter xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.region</name> + <description> + The region part of the top-level locale of the document + </description> +</parameter> + +<xsl:param name="gettext.region"> + <xsl:variable name="aft" select="substring-after($gettext.locale, '_')"/> + <xsl:choose> + <xsl:when test="contains($aft, '@')"> + <xsl:value-of select="substring-before($aft, '@')"/> + </xsl:when> + <xsl:when test="contains($aft, '.')"> + <xsl:value-of select="substring-before($aft, '.')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$aft"/> + </xsl:otherwise> + </xsl:choose> +</xsl:param> + + +<!-- == gettext.variant ==================================================== --> + +<parameter xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.variant</name> + <description> + The variant part of the top-level locale of the document + </description> +</parameter> + +<xsl:param name="gettext.variant"> + <xsl:variable name="aft" select="substring-after($gettext.locale, '@')"/> + <xsl:choose> + <xsl:when test="contains($aft, '.')"> + <xsl:value-of select="substring-before($aft, '.')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$aft"/> + </xsl:otherwise> + </xsl:choose> +</xsl:param> + + +<!-- == gettext.charset ==================================================== --> + +<parameter xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.charset</name> + <description> + The charset part of the top-level locale of the document + </description> +</parameter> + +<xsl:param name="gettext.charset"> + <xsl:if test="contains($gettext.locale, '.')"> + <xsl:value-of select="substring-after($gettext.locale, '.')"/> + </xsl:if> +</xsl:param> + <!-- == gettext ============================================================ --> <template xmlns="http://www.gnome.org/~shaunm/xsldoc"> <name>gettext</name> - <FIXME/> + <description> + Look up a translated string + </description> + <parameter> + <name>msgid</name> + <description> + The id of the string to look up, usually the string in the C locale + </description> + </parameter> + <parameter> + <name>lang</name> + <description> + The locale to use when looking up the translated string + </description> + </parameter> + <parameter> + <name>lang_lang</name> + <description> + The language portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_region</name> + <description> + The region portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_variant</name> + <description> + The variant portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_charset</name> + <description> + The charset portion of the locale to use + </description> + </parameter> + <parameter> + <name>number</name> + <description> + The cardinality for plural-form lookups + </description> + </parameter> + <parameter> + <name>form</name> + <description> + The form name for plural-form lookups + </description> + </parameter> </template> <xsl:template name="gettext"> <xsl:param name="msgid"/> <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> + <xsl:param name="lang_lang"> + <xsl:call-template name="gettext.get.language"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_region"> + <xsl:call-template name="gettext.get.region"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_variant"> + <xsl:call-template name="gettext.get.variant"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_charset"> + <xsl:call-template name="gettext.get.charset"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="number"/> + <xsl:param name="form"> + <xsl:call-template name="gettext.plural_form"> + <xsl:with-param name="number" select="$number"/> + <xsl:with-param name="lang" select="$lang"/> + <xsl:with-param name="lang_lang" select="$lang_lang"/> + <xsl:with-param name="lang_region" select="$lang_region"/> + <xsl:with-param name="lang_variant" select="$lang_variant"/> + <xsl:with-param name="lang_charset" select="$lang_charset"/> + </xsl:call-template> + </xsl:param> <xsl:for-each select="$l10n"> <xsl:variable name="msg" select="key('msgid', $msgid)"/> - <!-- - FIXME! - Language codes: en_US@Latn.UTF8 - We can ignore the encoding thing, so we have language, dialect, and charset. - Sort by the following order, and fallback as needed: - en_US@Latn en@Latn en_US en - --> + <xsl:choose> - <xsl:when test="$msg/msgstr[@xml:lang = $lang]"> - <xsl:value-of select="$msg/msgstr[@xml:lang = $lang]"/> + <!-- fe_fi@fo.fum --> + <xsl:when test="($lang_region and $lang_variant and $lang_charset) and + $msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '@', $lang_variant, '.', $lang_charset)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '@', $lang_variant, '.', $lang_charset)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe_fi@fo --> + <xsl:when test="($lang_region and $lang_variant) and + $msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '@', $lang_variant)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '@', $lang_variant)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe@fo.fum --> + <xsl:when test="($lang_variant and $lang_charset) and + $msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '@', $lang_variant, '.', $lang_charset)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '@', $lang_variant, '.', $lang_charset)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe@fo --> + <xsl:when test="($lang_variant) and + $msg/msg:msgstr[@xml:lang = concat($lang_lang, '@', $lang_variant)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '@', $lang_variant)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe_fi.fum --> + <xsl:when test="($lang_region and $lang_charset) and + $msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '.', $lang_charset)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region, '.', $lang_charset)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe_fi --> + <xsl:when test="($lang_region) and + $msg/msg:msgstr[@xml:lang = concat($lang_lang, '_', $lang_region)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '_', $lang_region)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- fe.fum --> + <xsl:when test="($lang_charset) and + $msg/msg:msgstr[@xml:lang = concat($lang_lang, '.', $lang_charset)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param + name="msgstr" select="$msg/msg:msgstr[@xml:lang = concat( + $lang_lang, '.', $lang_charset)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> </xsl:when> - <xsl:when test="$msg/msgstr[@xml:lang = 'C']"> - <xsl:value-of select="$msg/msgstr[@xml:lang = 'C']"/> + <!-- fe --> + <xsl:when test="$msg/msg:msgstr[@xml:lang = $lang_lang]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param name="msgstr" select="$msg/msg:msgstr[@xml:lang = $lang_lang]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> </xsl:when> - <xsl:when test="$msg/msgstr[not(@xml:lang)]"> - <xsl:value-of select="$msg/msgstr[not(@xml:lang)]"/> + <!-- "C" --> + <xsl:when test="$msg/msg:msgstr[@xml:lang = 'C']"> + <xsl:call-template name="gettext.get"> + <xsl:with-param name="msgstr" select="$msg/msg:msgstr[@xml:lang = 'C']"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> + </xsl:when> + <!-- not() --> + <xsl:when test="$msg/msg:msgstr[not(@xml:lang)]"> + <xsl:call-template name="gettext.get"> + <xsl:with-param name="msgstr" select="$msg/msg:msgstr[not(@xml:lang)]"/> + <xsl:with-param name="form" select="$form"/> + </xsl:call-template> </xsl:when> <xsl:otherwise> - <xsl:message> - <xsl:text>No translation available for string '</xsl:text> - <xsl:value-of select="$msgid"/> - <xsl:text>'.</xsl:text> - </xsl:message> - <xsl:value-of select="$msgid"/> + <xsl:message> + <xsl:text>No translation available for string '</xsl:text> + <xsl:value-of select="$msgid"/> + <xsl:text>'.</xsl:text> + </xsl:message> + <xsl:value-of select="$msgid"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> +<xsl:template name="gettext.get" doc:private="true"> + <xsl:param name="msgstr"/> + <xsl:param name="form"/> + <xsl:choose> + <xsl:when test="$msgstr/msg:msgstr[@form]"> + <xsl:choose> + <xsl:when test="$msgstr/msg:msgstr[@form = $form]"> + <xsl:value-of select="$msgstr/msg:msgstr[@form = $form]"/> + </xsl:when> + <xsl:when test="$msgstr/msg:msgstr[not(@form)]"> + <xsl:value-of select="$msgstr/msg:msgstr[not(@form)]"/> + </xsl:when> + <xsl:otherwise> + <xsl:message> + <xsl:text>No translation for </xsl:text> + <xsl:value-of select="$msgstr/preceding-sibling::msg:msgid"/> + <xsl:text> with plural form </xsl:text> + <xsl:value-of select="$form"/> + </xsl:message> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$msgstr"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + -<!-- == ngettext =========================================================== --> +<!-- == gettext.plural_form ================================================ --> <template xmlns="http://www.gnome.org/~shaunm/xsldoc"> - <name>ngettext</name> - <FIXME/> + <name>gettext</name> + <description> + Extract the plural form string for a cardinality + </description> + <parameter> + <name>number</name> + <description> + The cardinality of plural form + </description> + </parameter> + <parameter> + <name>lang</name> + <description> + The locale to use when looking up the translated string + </description> + </parameter> + <parameter> + <name>lang_lang</name> + <description> + The language portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_region</name> + <description> + The region portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_variant</name> + <description> + The variant portion of the locale to use + </description> + </parameter> + <parameter> + <name>lang_charset</name> + <description> + The charset portion of the locale to use + </description> + </parameter> </template> -<xsl:template name="ngettext"> - <xsl:param name="msgid"/> - <xsl:param name="msgid_plural"/> - <xsl:param name="num" select="1"/> - <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> +<xsl:template name="gettext.plural_form"> + <xsl:param name="number" select="1"/> + <xsl:param name="lang" select="$gettext.locale"/> + <xsl:param name="lang_lang"> + <xsl:call-template name="gettext.get.language"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_region"> + <xsl:call-template name="gettext.get.region"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_variant"> + <xsl:call-template name="gettext.get.variant"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> + <xsl:param name="lang_charset"> + <xsl:call-template name="gettext.get.charset"> + <xsl:with-param name="lang" select="$lang"/> + </xsl:call-template> + </xsl:param> - <xsl:call-template name="gettext"> - <xsl:with-param name="msgid"> - <xsl:choose> - <xsl:when test="$num = 1"> - <xsl:value-of select="$msgid"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="$msgid_plural"/> - </xsl:otherwise> - </xsl:choose> - </xsl:with-param> - <xsl:with-param name="lang" select="$lang"/> - </xsl:call-template> + <xsl:choose> + <xsl:when test="$num = 1"> + <xsl:text>singular</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>plural</xsl:text> + </xsl:otherwise> + </xsl:choose> </xsl:template> -<!-- ======================================================================= --> +<!-- == gettext.get.language =============================================== --> -<!-- ======================================================================= --> - -<xsl:template name="format.header.prefix.named" doc:private="true"> - <xsl:param name="header"/> - <xsl:value-of select="concat($header, '  ')"/> -</xsl:template> - -<xsl:template name="format.header.prefix.unnamed" doc:private="true"> - <xsl:param name="header"/> - <xsl:value-of select="concat($header, '  ')"/> -</xsl:template> +<template xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.get.language</name> + <description> + Extract the language part of a locale + </description> + <parameter> + <name>lang</name> + <description> + The locale string from which to extract the language string + </description> + </parameter> +</template> -<xsl:template name="format.header" doc:private="true"> - <xsl:param name="header"/> - <xsl:param name="number"/> +<xsl:template name="gettext.get.language"> + <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> <xsl:choose> - <xsl:when test="string-length($number) > 0"> - <xsl:value-of select="concat($header, ' ', $number)"/> + <xsl:when test="$lang = $gettext.locale"> + <xsl:value-of select="$gettext.language"/> + </xsl:when> + <xsl:when test="contains($lang, '_')"> + <xsl:value-of select="substring-before($lang, '_')"/> + </xsl:when> + <xsl:when test="contains($lang, '@')"> + <xsl:value-of select="substring-before($lang, '@')"/> + </xsl:when> + <xsl:when test="contains($lang, '_')"> + <xsl:value-of select="substring-before($lang, '@')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="$header"/> + <xsl:value-of select="$lang"/> </xsl:otherwise> </xsl:choose> </xsl:template> -<!-- ======================================================================= --> +<!-- == gettext.get.region ================================================= --> -<xsl:template name="plural" doc:private="true"> - <xsl:param name="num" select="1"/> - <xsl:param name="lang" select="$lang"/> +<template xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.get.region</name> + <description> + Extract the region part of a locale + </description> + <parameter> + <name>lang</name> + <description> + The locale string from which to extract the region string + </description> + </parameter> +</template> +<xsl:template name="gettext.get.region"> + <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> <xsl:choose> - <!-- cs --> - <xsl:when test="$lang = 'cs'"> + <xsl:when test="$lang = $gettext.locale"> + <xsl:value-of select="$gettext.region"/> + </xsl:when> + <xsl:when test="contains($lang, '_')"> + <xsl:variable name="aft" select="substring-after($lang, '_')"/> <xsl:choose> - <xsl:when test="($num mod 10 = 1) and ($num mod 100 != 11)"> - <xsl:value-of select="0"/> - </xsl:when> - <xsl:when test=" - ($num mod 10 >= 2) and ($num mod 10 <= 4) and - (($num mod 100 < 10) or ($num mod 100 >=20)) - "> - <xsl:value-of select="1"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="2"/> - </xsl:otherwise> + <xsl:when test="contains($aft, '@')"> + <xsl:value-of select="substring-before($aft, '@')"/> + </xsl:when> + <xsl:when test="contains($aft, '.')"> + <xsl:value-of select="substring-before($aft, '.')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$aft"/> + </xsl:otherwise> </xsl:choose> </xsl:when> + </xsl:choose> +</xsl:template> - <!-- ja --> - <xsl:when test="$lang = 'ja'"> - <xsl:value-of select="0"/> - </xsl:when> - <!-- sr sr@Latn --> - <xsl:when test="$lang = 'sr' or $lang = 'sr@Latn'"> +<!-- == gettext.get.variant ================================================ --> + +<template xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.get.variant</name> + <description> + Extract the variant part of a locale + </description> + <parameter> + <name>lang</name> + <description> + The locale string from which to extract the variant string + </description> + </parameter> +</template> + +<xsl:template name="gettext.get.variant"> + <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> + <xsl:choose> + <xsl:when test="$lang = $gettext.locale"> + <xsl:value-of select="$gettext.variant"/> + </xsl:when> + <xsl:when test="contains($lang, '@')"> + <xsl:variable name="aft" select="substring-after($lang, '@')"/> <xsl:choose> - <xsl:when test="($num mod 10 = 1) and ($num mod 100 != 11)"> - <xsl:value-of select="0"/> - </xsl:when> - <xsl:when test=" - ($num mod 10 >= 2) and ($num mod 10 <= 4) and - (($num mod 100 < 10) or ($num mod 100 >=20)) - "> - <xsl:value-of select="1"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="2"/> - </xsl:otherwise> + <xsl:when test="contains($aft, '.')"> + <xsl:value-of select="substring-before($aft, '.')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$aft"/> + </xsl:otherwise> </xsl:choose> </xsl:when> + </xsl:choose> +</xsl:template> - <!-- C --> - <xsl:otherwise> - <xsl:choose> - <xsl:when test="$num = 1"> - <xsl:value-of select="0"/> - </xsl:when> - <xsl:otherwise> - <xsl:value-of select="1"/> - </xsl:otherwise> - </xsl:choose> - </xsl:otherwise> + +<!-- == gettext.get.charset ================================================ --> + +<template xmlns="http://www.gnome.org/~shaunm/xsldoc"> + <name>gettext.get.charset</name> + <description> + Extract the charset part of a locale + </description> + <parameter> + <name>lang</name> + <description> + The locale string from which to extract the charset string + </description> + </parameter> +</template> + +<xsl:template name="gettext.get.charset"> + <xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang"/> + <xsl:choose> + <xsl:when test="$lang = $gettext.locale"> + <xsl:value-of select="$gettext.charset"/> + </xsl:when> + <xsl:when test="contains($lang, '.')"> + <xsl:value-of select="substring-after($lang, '.')"/> + </xsl:when> </xsl:choose> </xsl:template> diff --git a/xslt/gettext/l10n.xml.in b/xslt/gettext/l10n.xml.in index ad3e48d..eb89fdb 100644 --- a/xslt/gettext/l10n.xml.in +++ b/xslt/gettext/l10n.xml.in @@ -1,31 +1,6 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="utf-8"?><!-- -*- indent-tabs-mode: nil -*- --> -<l10n> - -<msg> - <!-- LEFT DOUBLE QUOTATION MARK - The opening quotation mark for outer quotes. --> - <msgid>“</msgid> - <_msgstr>“</_msgstr> -</msg> -<msg> - <!-- RIGHT DOUBLE QUOTATION MARK - The closing quotation mark for outer quotes. --> - <msgid>”</msgid> - <_msgstr>”</_msgstr> -</msg> -<msg> - <!-- LEFT SINGLE QUOTATION MARK - The opening quotation mark for inner quotes. --> - <msgid>‘</msgid> - <_msgstr>‘</_msgstr> -</msg> -<msg> - <!-- RIGHT SINGLE QUOTATION MARK - The closing quotation mark for inner quotes. --> - <msgid>’</msgid> - <_msgstr>’</_msgstr> -</msg> +<l10n xmlns="http://www.gnome.org/~shaunm/gnome-doc-utils/xsl-format"> <msg> <!-- Link to the titlepage of a <article> --> @@ -97,16 +72,6 @@ <_msgstr>Affiliation</_msgstr> </msg> <msg> - <!-- Used for the <appendix> element. --> - <msgid>Appendix</msgid> - <_msgstr>Appendix</_msgstr> -</msg> -<msg> - <!-- Used for the <article> element. --> - <msgid>Article</msgid> - <_msgstr>Article</_msgstr> -</msg> -<msg> <!-- This is an abbreviated form of 'Message Audience'. Feel free to use the same word/phrase for both. --> <msgid>Audience</msgid> @@ -123,26 +88,11 @@ <_msgstr>Authors</_msgstr> </msg> <msg> - <!-- Used for the <bibliography> element. --> - <msgid>Bibliography</msgid> - <_msgstr>Bibliography</_msgstr> -</msg> -<msg> - <!-- Used for the <book> element. --> - <msgid>Book</msgid> - <_msgstr>Book</_msgstr> -</msg> -<msg> <!-- Used for the <caution> element. --> <msgid>Caution</msgid> <_msgstr>Caution</_msgstr> </msg> <msg> - <!-- Used for the <chapter> element. --> - <msgid>Chapter</msgid> - <_msgstr>Chapter</_msgstr> -</msg> -<msg> <!-- Used for the <colophon> element. --> <msgid>Colophon</msgid> <_msgstr>Colophon</_msgstr> @@ -203,21 +153,6 @@ <_msgstr>Email</_msgstr> </msg> <msg> - <!-- Used for the <example> element. --> - <msgid>Example</msgid> - <_msgstr>Example</_msgstr> -</msg> -<msg> - <!-- Used for the <figure> element. --> - <msgid>Figure</msgid> - <_msgstr>Figure</_msgstr> -</msg> -<msg> - <!-- Used for the <glossary> element. --> - <msgid>Glossary</msgid> - <_msgstr>Glossary</_msgstr> -</msg> -<msg> <!-- Used for the <important> element. --> <msgid>Important</msgid> <_msgstr>Important</_msgstr> @@ -275,11 +210,6 @@ <_msgstr>Other Contributors</_msgstr> </msg> <msg> - <!-- Used for the <part> element. --> - <msgid>Part</msgid> - <_msgstr>Part</_msgstr> -</msg> -<msg> <!-- Used for the <preface> element. --> <msgid>Preface</msgid> <_msgstr>Preface</_msgstr> @@ -300,16 +230,6 @@ <_msgstr>Reference</_msgstr> </msg> <msg> - <!-- Used for the <refentry> element. --> - <msgid>Reference Entry</msgid> - <_msgstr>Reference Entry</_msgstr> -</msg> -<msg> - <!-- Used for the <refsect*> elements. --> - <msgid>Reference Section</msgid> - <_msgstr>Reference Section</_msgstr> -</msg> -<msg> <!-- Used for the <releaseinfo> element. --> <msgid>Release Information</msgid> <_msgstr>Release Information</_msgstr> @@ -320,11 +240,6 @@ <_msgstr>Revision History</_msgstr> </msg> <msg> - <!-- Used for the <sect*> elements. --> - <msgid>Section</msgid> - <_msgstr>Section</_msgstr> -</msg> -<msg> <!-- Used for the <see> element. --> <msgid>See</msgid> <_msgstr>See</_msgstr> @@ -340,11 +255,6 @@ <_msgstr>Set Index</_msgstr> </msg> <msg> - <!-- Used for the <table> element. --> - <msgid>Table</msgid> - <_msgstr>Table</_msgstr> -</msg> -<msg> <!-- Used for a link to a table of contents. --> <msgid>Table of Contents</msgid> <_msgstr>Table of Contents</_msgstr> |