Commit 4e30c918 authored by Shaun McCance's avatar Shaun McCance
Browse files

Avoid use of global l10n.locale parameter

Documents can have different languages at different levels. This is
especially true with Mallard stack files, which could incorporate
some translated documents, as well as some that have not yet been
translated. Using a single global parameter completely breaks this.
parent cef8f0c8
......@@ -5,12 +5,16 @@
<link type="guide" xref="templates" group="html"/>
<desc>Stub to output extra content before a link trail.</desc>
<link type="guide" xref="stubs" group="html"/>
<revision version="3.28" date="2017-05-24" status="final"/>
<revision version="42" date="2021-10-30" status="final"/>
</info>
<title>html.linktrails.prefix</title>
<synopsis>
<title>Parameters</title>
<terms>
<item>
<title><code>$page</code></title>
<p>The source element for which an output page is being made.</p>
</item>
<item>
<title><code>$node</code></title>
<p>A source-specific element providing information about the link trail.</p>
......@@ -20,4 +24,7 @@
<p>This template is a stub. It is called by templates that output link trails
before the normal links are output. This template is useful for adding extra
site links at the beginning of each link trail.</p>
<note style="plain">
<p>The <code>$page</code> parameter was added in version 42.</p>
</note>
</page>
......@@ -4,26 +4,35 @@
<link type="guide" xref="l10n" group="templates"/>
<link type="guide" xref="templates" group="l10n"/>
<desc>Determine the text direction for a language.</desc>
<revision version="3.18" date="2015-08-13" status="final"/>
<revision version="42" date="2021-10-30" status="final"/>
</info>
<title>l10n.direction</title>
<synopsis>
<title>Parameters</title>
<terms>
<item>
<title><code>$node</code></title>
<p>The node to find the direction for.</p>
</item>
<item>
<title><code>$lang</code></title>
<p>The locale to use to determine the text direction.</p>
</item>
</terms>
</synopsis>
<p>This template returns the text direction for the language <code>$lang</code>. It returns
<sys>"ltr"</sys> for left-to-right languages and <sys>"rtl"</sys> for right-to-left languages.
If <code>$lang</code> is not provided, it defaults to <code xref="l10n.locale">l10n.locale</code>, the top-level locale
of the document.</p>
<p>This template returns the text direction for the language <code>$lang</code>. If <code>$lang</code> is
not provided, it looks for the nearest node to <code>$node</code> with a locale attribute,
either <sys>xml:lang</sys> or <sys>lang</sys>.</p>
<p>This template returns <sys>"ltr"</sys> for left-to-right languages and <sys>"rtl"</sys> for
right-to-left languages.</p>
<p>This template calls <code xref="l10n.gettext">l10n.gettext</code> with the string <sys>default:LTR</sys> in the domain
<sys>yelp-xsl</sys>. The language is right-to-left if the string <sys>default:RTL</sys> is
returned. Otherwise, it is left-to-right. (This particular string is used to
match the string used in GTK+, enabling translation memory.)</p>
<note style="plain">
<p>The <code>$node</code> parameter was added in version 42, and the default value of the
<code>$lang</code> parameter was changed accordingly.</p>
</note>
<list style="compact">
<title>Calls Parameters</title>
<item>
......
......@@ -10,4 +10,9 @@
<p>This parameter provides the top-level locale of the document, taken from either
the <sys>xml:lang</sys> or the <sys>lang</sys> parameter of the root element. It holds the
locale exactly as specified in the document, with no normalization.</p>
<note style="warning">
<p>This parameter is deprecated. When processing multiple pages in a stack, you
cannot rely on a single global locale. Instead, when you need a locale, you
should look for an <sys>ancestor-or-self</sys> node with the appropriate attribute.</p>
</note>
</page>
......@@ -4,12 +4,16 @@
<link type="guide" xref="mal2html-page" group="templates"/>
<link type="guide" xref="templates" group="mal2html"/>
<desc>Output a link and the following links in a link trail.</desc>
<revision version="3.4" date="2011-11-19" status="final"/>
<revision version="42" date="2021-11-19" status="final"/>
</info>
<title>mal2html.page.linktrails.link</title>
<synopsis>
<title>Parameters</title>
<terms>
<item>
<title><code>$page</code></title>
<p>The source element for which an output page is being made.</p>
</item>
<item>
<title><code>$node</code></title>
<p>A <sys>link</sys> element from <code xref="mal.link.linktrails">mal.link.linktrails</code>.</p>
......@@ -27,6 +31,9 @@
<p>The <code>$direction</code> parameter specifies the current text directionality. If not
provided, it is computed automatically with <code xref="l10n.direction">l10n.direction</code>. It determines the
separators used between links.</p>
<note style="plain">
<p>The <code>$page</code> parameter was added in version 42.</p>
</note>
<list style="compact">
<title>Calls Templates</title>
<item>
......
......@@ -4,12 +4,16 @@
<link type="guide" xref="mal2html-page" group="templates"/>
<link type="guide" xref="templates" group="mal2html"/>
<desc>Output one trail of guide links.</desc>
<revision version="3.20" date="2015-09-19" status="final"/>
<revision version="42" date="2021-10-30" status="final"/>
</info>
<title>mal2html.page.linktrails.trail</title>
<synopsis>
<title>Parameters</title>
<terms>
<item>
<title><code>$page</code></title>
<p>The source element for which an output page is being made.</p>
</item>
<item>
<title><code>$node</code></title>
<p>A <sys>link</sys> element from <code xref="mal.link.linktrails">mal.link.linktrails</code>.</p>
......@@ -20,6 +24,9 @@
single link trail. It calls <code xref="html.linktrails.prefix">html.linktrails.prefix</code> (by way of
<code xref="mal2html.page.linktrails.trail.prefix">mal2html.page.linktrails.trail.prefix</code>) to output a custom boilerplate prefix,
then calls <code xref="mal2html.page.linktrails.link">mal2html.page.linktrails.link</code> to output the actual links.</p>
<note style="plain">
<p>The <code>$page</code> parameter was added in version 42.</p>
</note>
<list style="compact">
<title>Calls Templates</title>
<item>
......
......@@ -7,10 +7,14 @@
</info>
<title>mal2html.page.linktrails.trail.prefix</title>
<p>:Stub: true
@revision[version=3.20 date=2015-09-17 status=final]</p>
@revision[version=42 date=2021-10-30 status=final]</p>
<synopsis>
<title>Parameters</title>
<terms>
<item>
<title><code>$page</code></title>
<p>The source element for which an output page is being made.</p>
</item>
<item>
<title><code>$node</code></title>
<p>A <sys>link</sys> element from <code xref="mal.link.linktrails">mal.link.linktrails</code>.</p>
......@@ -23,6 +27,9 @@
each link trail before the normal links are output with
<code xref="mal2html.page.linktrails.link">mal2html.page.linktrails.link</code>. This template is useful for adding extra site
links at the beginning of each link trail.</p>
<note style="plain">
<p>The <code>$page</code> parameter was added in version 42.</p>
</note>
<list style="compact">
<title>Calls Templates</title>
<item>
......
......@@ -878,16 +878,21 @@ trails would otherwise be present.
html.linktrails.prefix
Stub to output extra content before a link trail.
@xsl:stub
@revision[version=3.28 date=2017-05-24 status=final]
@revision[version=42 date=2021-10-30 status=final]
[xsl:params]
$page: The source element for which an output page is being made.
$node: A source-specific element providing information about the link trail.
This template is a stub. It is called by templates that output link trails
before the normal links are output. This template is useful for adding extra
site links at the beginning of each link trail.
[note .plain]
The $page parameter was added in version 42.
-->
<xsl:template name="html.linktrails.prefix">
<xsl:param name="page" select="."/>
<xsl:param name="node" select="."/>
</xsl:template>
......@@ -1104,7 +1109,9 @@ dimensions. All parameters can be automatically computed if not provided.
<xsl:template name="html.css">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......@@ -1146,7 +1153,9 @@ calls the template {html.css.custom}.
<xsl:template name="html.css.content">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......@@ -1248,7 +1257,9 @@ All parameters can be automatically computed if not provided.
<xsl:template name="html.css.core">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......@@ -1296,7 +1307,9 @@ All parameters can be automatically computed if not provided.
<xsl:template name="html.css.elements">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......@@ -1411,7 +1424,9 @@ All parameters can be automatically computed if not provided.
<xsl:template name="html.css.syntax">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......@@ -1453,7 +1468,9 @@ template to provide additional CSS that will be used by all HTML output.
<xsl:template name="html.css.custom">
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......
......@@ -63,6 +63,11 @@ The top-level locale of the document.
This parameter provides the top-level locale of the document, taken from either
the `xml:lang` or the `lang` parameter of the root element. It holds the
locale exactly as specified in the document, with no normalization.
[note .warning]
This parameter is deprecated. When processing multiple pages in a stack, you
cannot rely on a single global locale. Instead, when you need a locale, you
should look for an `ancestor-or-self` node with the appropriate attribute.
-->
<xsl:param name="l10n.locale">
<xsl:choose>
......@@ -508,23 +513,43 @@ as well as the plural rules in the Unicode CLDR.
<!--**==========================================================================
l10n.direction
Determine the text direction for a language.
@revision[version=3.18 date=2015-08-13 status=final]
@revision[version=42 date=2021-10-30 status=final]
[xsl:params]
$node: The node to find the direction for.
$lang: The locale to use to determine the text direction.
This template returns the text direction for the language $lang. It returns
`"ltr"` for left-to-right languages and `"rtl"` for right-to-left languages.
If $lang is not provided, it defaults to {l10n.locale}, the top-level locale
of the document.
This template returns the text direction for the language $lang. If $lang is
not provided, it looks for the nearest node to $node with a locale attribute,
either `xml:lang` or `lang`.
This template returns `"ltr"` for left-to-right languages and `"rtl"` for
right-to-left languages.
This template calls {l10n.gettext} with the string `default:LTR` in the domain
`yelp-xsl`. The language is right-to-left if the string `default:RTL` is
returned. Otherwise, it is left-to-right. (This particular string is used to
match the string used in GTK+, enabling translation memory.)
[note .plain]
The $node parameter was added in version 42, and the default value of the
$lang parameter was changed accordingly.
-->
<xsl:template name="l10n.direction">
<xsl:param name="lang" select="$l10n.locale"/>
<xsl:param name="node" select="."/>
<xsl:param name="lang">
<xsl:choose>
<xsl:when test="$node/ancestor-or-self::*[@xml:lang]">
<xsl:value-of select="$node/ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
</xsl:when>
<xsl:when test="$node/ancestor-or-self::*[@lang]">
<xsl:value-of select="$node/ancestor-or-self::*[@lang][1]/@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$l10n.locale"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:variable name="direction">
<xsl:for-each select="/*">
<xsl:call-template name="l10n.gettext">
......
......@@ -72,7 +72,9 @@ This template was added in version 40.
<xsl:param name="file"/>
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:param>
<xsl:param name="left">
<xsl:call-template name="l10n.align.start">
......
......@@ -387,7 +387,9 @@ html.sidebar.sections.mode
<xsl:template mode="html.header.mode" match="&map_topicref;">
<xsl:variable name="node" select="."/>
<xsl:variable name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="sep">
<xsl:choose>
......
......@@ -45,7 +45,9 @@ as that template's `node` parameter.
<xsl:template name="db2html.links.linktrail">
<xsl:param name="node" select="."/>
<xsl:variable name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$node/ancestor::*">
......
......@@ -185,9 +185,7 @@ an `xref` or `href` attribute.
<xsl:template mode="mal2html.inline.content.mode" match="mal:guiseq">
<xsl:variable name="arrow">
<xsl:variable name="dir">
<xsl:call-template name="l10n.direction">
<xsl:with-param name="lang" select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
</xsl:call-template>
<xsl:call-template name="l10n.direction"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$dir = 'rtl'">
......
......@@ -367,7 +367,7 @@ neighboring `item` elements, and passes that prefix to child elements.
<xsl:if test="$lines">
<xsl:variable name="dir">
<xsl:call-template name="l10n.direction">
<xsl:with-param name="lang" select="$item/ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
<xsl:with-param name="node" select="$item"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="translate(translate(translate(translate(
......
......@@ -251,7 +251,9 @@ on each one. Otherwise, it calls the stub template {mal2html.page.linktrails.emp
<xsl:sort select="(.//mal:title[@type='sort'])[3]"/>
<xsl:sort select="(.//mal:title[@type='sort'])[4]"/>
<xsl:sort select="(.//mal:title[@type='sort'])[5]"/>
<xsl:call-template name="mal2html.page.linktrails.trail"/>
<xsl:call-template name="mal2html.page.linktrails.trail">
<xsl:with-param name="page" select="$node"/>
</xsl:call-template>
</xsl:for-each>
</div>
</xsl:when>
......@@ -292,23 +294,30 @@ trails would otherwise be present.
<!--**==========================================================================
mal2html.page.linktrails.trail
Output one trail of guide links.
@revision[version=3.20 date=2015-09-19 status=final]
@revision[version=42 date=2021-10-30 status=final]
[xsl:params]
$page: The source element for which an output page is being made.
$node: A `link` element from {mal.link.linktrails}.
This template outputs an HTML `div` element containing all the links in a
single link trail. It calls {html.linktrails.prefix} (by way of
{mal2html.page.linktrails.trail.prefix}) to output a custom boilerplate prefix,
then calls {mal2html.page.linktrails.link} to output the actual links.
[note .plain]
The $page parameter was added in version 42.
-->
<xsl:template name="mal2html.page.linktrails.trail">
<xsl:param name="page" select="."/>
<xsl:param name="node" select="."/>
<div class="trail">
<xsl:call-template name="mal2html.page.linktrails.trail.prefix">
<xsl:with-param name="page" select="$page"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
<xsl:call-template name="mal2html.page.linktrails.link">
<xsl:with-param name="page" select="$page"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</div>
......@@ -319,9 +328,10 @@ then calls {mal2html.page.linktrails.link} to output the actual links.
mal2html.page.linktrails.trail.prefix
Deprecated stub to output extra content before a link trail.
:Stub: true
@revision[version=3.20 date=2015-09-17 status=final]
@revision[version=42 date=2021-10-30 status=final]
[xsl:params]
$page: The source element for which an output page is being made.
$node: A `link` element from {mal.link.linktrails}.
This template is deprecated. Use {html.linktrails.prefix} instead. By default,
......@@ -331,10 +341,15 @@ This template is a stub. It is called by {mal2html.page.linktrails.trail} for
each link trail before the normal links are output with
{mal2html.page.linktrails.link}. This template is useful for adding extra site
links at the beginning of each link trail.
[note .plain]
The $page parameter was added in version 42.
-->
<xsl:template name="mal2html.page.linktrails.trail.prefix">
<xsl:param name="page" select="."/>
<xsl:param name="node" select="."/>
<xsl:call-template name="html.linktrails.prefix">
<xsl:with-param name="page" select="$page"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:template>
......@@ -343,9 +358,10 @@ links at the beginning of each link trail.
<!--**==========================================================================
mal2html.page.linktrails.link
Output a link and the following links in a link trail.
@revision[version=3.4 date=2011-11-19 status=final]
@revision[version=42 date=2021-11-19 status=final]
[xsl:params]
$page: The source element for which an output page is being made.
$node: A `link` element from {mal.link.linktrails}.
$direction: The text directionality.
......@@ -357,11 +373,17 @@ element, then calls itself recursively on the child `link` element, if it exists
The $direction parameter specifies the current text directionality. If not
provided, it is computed automatically with {l10n.direction}. It determines the
separators used between links.
[note .plain]
The $page parameter was added in version 42.
-->
<xsl:template name="mal2html.page.linktrails.link">
<xsl:param name="page" select="."/>
<xsl:param name="node" select="."/>
<xsl:param name="direction">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$page"/>
</xsl:call-template>
</xsl:param>
<a class="trail">
<xsl:attribute name="href">
......@@ -397,6 +419,7 @@ separators used between links.
</xsl:if>
<xsl:for-each select="$node/mal:link">
<xsl:call-template name="mal2html.page.linktrails.link">
<xsl:with-param name="page" select="$page"/>
<xsl:with-param name="direction" select="$direction"/>
</xsl:call-template>
</xsl:for-each>
......
......@@ -100,7 +100,9 @@ http://projectmallard.org/ui/1.0/ui_expanded.html</xsl:text>
<xsl:variable name="title_c" select="$node/mal:info/mal:title[@type = 'ui:collapsed'][1]"/>
<div class="yelp-data yelp-data-ui-expander">
<xsl:attribute name="dir">
<xsl:call-template name="l10n.direction"/>
<xsl:call-template name="l10n.direction">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="data-yelp-expanded">
<xsl:choose>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment