Debian Codegraph @

xslt/common/l10n.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see
15 <http://www.gnu.org/licenses/>.
16 -->
17
18 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
19 xmlns:msg="http://projects.gnome.org/yelp/gettext/"
20 xmlns:str="http://exslt.org/strings"
21 exclude-result-prefixes="msg str"
22 version="1.0">
23
24 <!--!!==========================================================================
25 Localized Strings
26 Templates for translated strings, with format strings and plural forms.
27 @revision[version=3.18 date=2015-07-24 status=final]
28
29 This stylesheet contains templates for getting localized strings, including
30 format strings and plural forms. Format strings are important for proper
31 localization, as constructing sentences from concatenation often produces
32 poor results in many languages.
33
34 By default, the templates in this stylesheet work on the translations shipped
35 with yelp-xsl, but the templates can be reused by yelp-xsl extensions (or even
36 entirely separate stylesheets) by installing XML files with the translations
37 under the domains subdirectory of the directory holding this file. The format
38 of the file is designed to work well with itstool's join mode.
39 -->
40
41
42 <!--++==========================================================================
43 l10n.msgstr.key
44 Get a translated message from an ID and a language.
45 @revision[version=3.4 date=2012-01-26 status=final]
46
47 This key indexes all message translations in a message catalog file. The elements
48 are indexed by the concatenation of the message id, the string `__LC__`, and the
49 `xml:lang` attribute converted to lowercase.
50 -->
51 <xsl:key name="l10n.msgstr.key" match="msg:msg/msg:msgstr"
52 use="concat(../@id, '__LC__',
53 translate(@xml:lang,
54 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
55 'abcdefghijklmnopqrstuvwxyz'))"/>
56
57
58 <!--@@==========================================================================
59 l10n.locale
60 The top-level locale of the document.
61 @revision[version=3.18 date=2015-08-13 status=final]
62
63 This parameter provides the top-level locale of the document, taken from either
64 the `xml:lang` or the `lang` parameter of the root element. It holds the
65 locale exactly as specified in the document, with no normalization.
66
67 [note .warning]
68 This parameter is deprecated. When processing multiple pages in a stack, you
69 cannot rely on a single global locale. Instead, when you need a locale, you
70 should look for an `ancestor-or-self` node with the appropriate attribute.
71 -->
72 <xsl:param name="l10n.locale">
73 <xsl:choose>
74 <xsl:when test="/*/@xml:lang">
75 <xsl:value-of select="/*/@xml:lang"/>
76 </xsl:when>
77 <xsl:when test="/*/@lang">
78 <xsl:value-of select="/*/@lang"/>
79 </xsl:when>
80 </xsl:choose>
81 </xsl:param>
82
83
84 <!--**==========================================================================
85 l10n.gettext
86 Look up the translation for a string.
87 @revision[version=3.18 date=2015-07-29 status=final]
88
89 [xsl:params]
90 $domain: The domain to look up the string in.
91 $msgid: The id of the string to look up, often the string in the C locale.
92 $lang: The locale to use when looking up the translated string.
93 $number: The cardinality for plural-form lookups.
94 $form: The form name for plural-form lookups.
95 $format: Whether to treat the result as a format string.
96 $node: A context node to pass to {l10n.format.mode}.
97 $string: A string to pass to {l10n.format.mode} for `msg:string` elements.
98
99 This template extracts a translated version of a source string. In simple cases,
100 the source string is exactly the string in $msgid, though in more complex
101 cases, the $msgid parameter is a separate unique identifier.
102
103 This template looks up the translation in a message catalog file based on the
104 $domain parameter. The file must be in a `domains` subdirectory relative to
105 the directory holding this stylesheet and be named the same as $domain with
106 the suffix `.xml`. This template will fail if no such file is found. By
107 default, the domain is `yelp-xsl` to reference the translations shipped with
108 these stylesheets. Extensions and third-party stylesheets, however, can use
109 this template by installing a file and passing the $domain parameter.
110
111 The message catalog file format is designed to work with the XML/PO translation
112 tool `itstool`, using its join mode to create a single polylingual file. There
113 is no tool to automatically extract messages from XSLT files. You must add
114 messages to the source catalog file when adding translatable strings.
115
116 The message catalog file contains a set of `msg` elements, one for each string
117 that needs translation. Each `msg` element has an `id` attribute. It is this
118 attribute that is matched against the $msgid parameter. Each `msg` element
119 then has one or more `msgstr` elements, each with an `xml:lang` attribute.
120 This template tries to find a best match language with the $lang parameter,
121 falling back to a `msgstr` element with no `xml:lang` attribute.
122
123 In a source message catalog file, put the string to be translated inside a
124 singleton `msgstr` element in each `msg` element, without an `xml:lang`
125 parameter. Add this element even if it is the same as the `id` attribute of
126 the `msg` element. These `msgstr` elements are what `itstool` uses to create
127 a PO file, and it provides the fallback string when no language matches.
128
129 The `xml:lang` attribute should contain an RFC 3066 language identifier, which
130 is different from the POSIX locale identifiers used by gettext. To accommodate
131 this difference, this stylesheet converts all identifiers to lowercase and
132 replaces the characters `_`, `@`, and `.` with the character `-`. If it
133 cannot find an exact match, it strips the part after the last `-` and looks
134 again. It repeats this as long as the identifier contains a `-` character.
135 If there is still no matching `msgstr` element, it looks for one with no
136 `xml:lang` attribute.
137
138 Sometimes you have to provide different versions of a string for different
139 cardinalities. While English and many other languages have singular and plural,
140 some languages have no plural forms, while others have as many as six. These
141 stylesheets use a numeric index for plural forms, similarly to gettext. To get
142 the string for a plural, pass the cardinality in the $number parameter. This
143 template gets an index for that number by calling {l10n.plural.form}. The
144 plural form index is in the $form parameter. You do not have to pass this
145 parameter. It will be computed automatically based on the $number parameter.
146
147 There is currently no support for editing plural forms using the standard PO
148 syntax. Instead, plurals are defined with an XML snippet. Instead of putting
149 the single translated message in the `msgstr` element, plural messages have
150 `msgstr` child elements of the `msgstr` element with the `xml:lang`
151 attribute. Each of these child `msgstr` elements has a `form` attribute that
152 holds the numeric index returned by {l10n.plural.form}. Translators must adapt
153 the XML snippet according to the plural rules and forms defined in this
154 stylesheet for their language.
155
156 Some translations aren't simple strings, but are instead format strings where
157 certain values are inserted. This template can handle format strings with XML
158 marker elements to signal where values should be substituted. These values
159 can be the result of applying templates.
160
161 To enable format strings, set the $format parameter to `true()`.
162 Instead of just returning the translated string, this template will
163 apply templates in the mode {l10n.format.mode} to the fragment contained in
164 the `msgstr` element.
165
166 The $node and $string parameters are passed to templates in
167 {l10n.format.mode}. This stylesheet contains matches in {l10n.format.mode}
168 for the marker elements `<string/>` and `<node/>`. The element
169 `<string/>` will be replaced by the string value of $string. The
170 element `<node/>` will apply templates without a mode to $node.
171 Text nodes are copied to the result in {l10n.format.mode}.
172
173 If you need any other behavior, add elements with any name of your choosing to
174 the format string, then match on those elements in {l10n.format.mode}. You will
175 be able to use the $node and $string parameters in your template. Try to
176 use a name that is unique.
177 -->
178 <xsl:template name="l10n.gettext">
179 <xsl:param name="domain" select="'yelp-xsl'"/>
180 <xsl:param name="msgid"/>
181 <xsl:param name="lang" select="(ancestor-or-self::*[@lang][1]/@lang |
182 ancestor-or-self::*[@xml:lang][1]/@xml:lang)
183 [last()]"/>
184 <xsl:param name="number"/>
185 <xsl:param name="form">
186 <xsl:if test="$number">
187 <xsl:call-template name="l10n.plural.form">
188 <xsl:with-param name="number" select="$number"/>
189 <xsl:with-param name="lang" select="$lang"/>
190 </xsl:call-template>
191 </xsl:if>
192 </xsl:param>
193 <xsl:param name="format" select="false()"/>
194 <xsl:param name="node" select="."/>
195 <xsl:param name="string"/>
196
197 <xsl:variable name="source" select="."/>
198 <xsl:variable name="normlang" select="translate($lang,
199 '[email protected]',
200 '---abcdefghijklmnopqrstuvwxyz')"/>
201 <xsl:for-each select="document(concat('domains/', $domain, '.xml'))">
202 <xsl:variable name="msg" select="key('l10n.msgstr.key',
203 concat($msgid, '__LC__', $normlang))"/>
204 <xsl:choose>
205 <xsl:when test="$msg">
206 <xsl:for-each select="$source">
207 <xsl:call-template name="l10n.gettext.msg">
208 <xsl:with-param name="msg" select="$msg"/>
209 <xsl:with-param name="form" select="$form"/>
210 <xsl:with-param name="node" select="$node"/>
211 <xsl:with-param name="string" select="$string"/>
212 <xsl:with-param name="format" select="$format"/>
213 </xsl:call-template>
214 </xsl:for-each>
215 </xsl:when>
216 <xsl:when test="contains($normlang, '-')">
217 <xsl:variable name="newlang">
218 <xsl:for-each select="str:split($normlang, '-')[position() != last()]">
219 <xsl:if test="position() != 1">
220 <xsl:text>-</xsl:text>
221 </xsl:if>
222 <xsl:value-of select="."/>
223 </xsl:for-each>
224 </xsl:variable>
225 <xsl:for-each select="$source">
226 <xsl:call-template name="l10n.gettext">
227 <xsl:with-param name="domain" select="$domain"/>
228 <xsl:with-param name="msgid" select="$msgid"/>
229 <xsl:with-param name="lang" select="$newlang"/>
230 <xsl:with-param name="number" select="$number"/>
231 <xsl:with-param name="form" select="$form"/>
232 <xsl:with-param name="node" select="$node"/>
233 <xsl:with-param name="string" select="$string"/>
234 <xsl:with-param name="format" select="$format"/>
235 </xsl:call-template>
236 </xsl:for-each>
237 </xsl:when>
238 <xsl:otherwise>
239 <xsl:variable name="cmsg" select="key('l10n.msgstr.key',
240 concat($msgid, '__LC__'))"/>
241 <xsl:choose>
242 <xsl:when test="$cmsg">
243 <xsl:for-each select="$source">
244 <xsl:call-template name="l10n.gettext.msg">
245 <xsl:with-param name="msg" select="$cmsg"/>
246 <xsl:with-param name="form" select="$form"/>
247 <xsl:with-param name="node" select="$node"/>
248 <xsl:with-param name="string" select="$string"/>
249 <xsl:with-param name="format" select="$format"/>
250 </xsl:call-template>
251 </xsl:for-each>
252 </xsl:when>
253 <xsl:otherwise>
254 <xsl:value-of select="$msgid"/>
255 </xsl:otherwise>
256 </xsl:choose>
257 </xsl:otherwise>
258 </xsl:choose>
259 </xsl:for-each>
260 </xsl:template>
261
262 <!-- FIXME: a bit of docs -->
263 <!--#* l10n.gettext.msg -->
264 <xsl:template name="l10n.gettext.msg">
265 <xsl:param name="msg"/>
266 <xsl:param name="form" select="''"/>
267 <xsl:param name="node" select="."/>
268 <xsl:param name="string"/>
269 <xsl:param name="format" select="false()"/>
270 <xsl:choose>
271 <xsl:when test="not($msg/msg:msgstr)">
272 <xsl:call-template name="l10n.gettext.msgstr">
273 <xsl:with-param name="msgstr" select="$msg"/>
274 <xsl:with-param name="node" select="$node"/>
275 <xsl:with-param name="string" select="$string"/>
276 <xsl:with-param name="format" select="$format"/>
277 </xsl:call-template>
278 </xsl:when>
279 <!-- FIXME: OPTIMIZE: this needs to be faster -->
280 <!-- FIXME: simplify -->
281 <xsl:when test="$form != ''">
282 <xsl:choose>
283 <xsl:when test="$msg/msg:msgstr[@form = $form]">
284 <xsl:call-template name="l10n.gettext.msgstr">
285 <xsl:with-param name="msgstr"
286 select="$msg/msg:msgstr[@form = $form][1]"/>
287 <xsl:with-param name="node" select="$node"/>
288 <xsl:with-param name="string" select="$string"/>
289 <xsl:with-param name="format" select="$format"/>
290 </xsl:call-template>
291 </xsl:when>
292 <xsl:when test="$msg/msg:msgstr[not(@form)]">
293 <xsl:call-template name="l10n.gettext.msgstr">
294 <xsl:with-param name="msgstr"
295 select="$msg/msg:msgstr[not(@form)][1]"/>
296 <xsl:with-param name="node" select="$node"/>
297 <xsl:with-param name="string" select="$string"/>
298 <xsl:with-param name="format" select="$format"/>
299 </xsl:call-template>
300 </xsl:when>
301 <xsl:otherwise>
302 <xsl:call-template name="l10n.gettext.msgstr">
303 <xsl:with-param name="msgstr" select="$msg/msg:msgstr[1]"/>
304 <xsl:with-param name="node" select="$node"/>
305 <xsl:with-param name="string" select="$string"/>
306 <xsl:with-param name="format" select="$format"/>
307 </xsl:call-template>
308 </xsl:otherwise>
309 </xsl:choose>
310 </xsl:when>
311 <xsl:otherwise>
312 <xsl:call-template name="l10n.gettext.msgstr">
313 <xsl:with-param name="msgstr" select="$msg/msg:msgstr[1]"/>
314 <xsl:with-param name="node" select="$node"/>
315 <xsl:with-param name="string" select="$string"/>
316 <xsl:with-param name="format" select="$format"/>
317 </xsl:call-template>
318 </xsl:otherwise>
319 </xsl:choose>
320 </xsl:template>
321
322 <!--#* l10n.gettext.msgstr -->
323 <xsl:template name="l10n.gettext.msgstr">
324 <xsl:param name="msgstr"/>
325 <xsl:param name="node" select="."/>
326 <xsl:param name="string"/>
327 <xsl:param name="format" select="false()"/>
328 <xsl:choose>
329 <xsl:when test="$format">
330 <xsl:apply-templates mode="l10n.format.mode" select="$msgstr/node()">
331 <xsl:with-param name="node" select="$node"/>
332 <xsl:with-param name="string" select="$string"/>
333 </xsl:apply-templates>
334 </xsl:when>
335 <xsl:otherwise>
336 <xsl:value-of select="$msgstr"/>
337 </xsl:otherwise>
338 </xsl:choose>
339 </xsl:template>
340
341
342 <!--**==========================================================================
343 l10n.plural.form
344 Extract the plural form index for a given cardinality.
345 @revision[version=3.18 date=2015-07-29 status=final]
346
347 [xsl:params]
348 $number: The cardinality of the plural form.
349 $lang: The locale to use when looking up the translated string.
350
351 This template returns a numeric index of a plural form for a given language,
352 similarly to how indexes are used in gettext PO files. Different languages have
353 different rules for plurals. Some languages have no plurals at all, while others
354 have as many as six different forms. This plural form index is used by
355 {l10n.gettext} to determine the correct string to use.
356
357 The rules in this template are hand-written. They are not taken from the PO
358 files. They are written by referencing the PO files in various GNOME modules,
359 as well as the plural rules in the Unicode CLDR.
360 -->
361 <xsl:template name="l10n.plural.form">
362 <xsl:param name="number" select="1"/>
363 <xsl:param name="lang" select="$l10n.locale"/>
364 <xsl:variable name="normlang" select="concat(translate($lang,
365 '[email protected]',
366 '---abcdefghijklmnopqrstuvwxyz'),
367 '-')"/>
368
369 <xsl:choose>
370 <!-- == pt_BR == -->
371 <xsl:when test="starts-with($normlang, 'pt-br-')">
372 <xsl:choose>
373 <xsl:when test="$number &gt; 1">
374 <xsl:text>0</xsl:text>
375 </xsl:when>
376 <xsl:otherwise>
377 <xsl:text>1</xsl:text>
378 </xsl:otherwise>
379 </xsl:choose>
380 </xsl:when>
381
382 <!-- == ar == -->
383 <xsl:when test="starts-with($normlang, 'ar-')">
384 <xsl:choose>
385 <xsl:when test="$number = 1">
386 <xsl:text>0</xsl:text>
387 </xsl:when>
388 <xsl:when test="$number = 2">
389 <xsl:text>1</xsl:text>
390 </xsl:when>
391 <xsl:when test="$number &gt;= 3 and $number &lt; 10">
392 <xsl:text>2</xsl:text>
393 </xsl:when>
394 <xsl:otherwise>
395 <xsl:text>3</xsl:text>
396 </xsl:otherwise>
397 </xsl:choose>
398 </xsl:when>
399
400 <!-- == be bs cs ru sr uk == -->
401 <xsl:when test="starts-with($normlang, 'be-') or starts-with($normlang, 'bs-') or
402 starts-with($normlang, 'cs-') or starts-with($normlang, 'ru-') or
403 starts-with($normlang, 'sr-') or starts-with($normlang, 'uk-') ">
404 <xsl:choose>
405 <xsl:when test="($number mod 10 = 1) and ($number mod 100 != 11)">
406 <xsl:text>0</xsl:text>
407 </xsl:when>
408 <xsl:when test="($number mod 10 &gt;= 2) and ($number mod 10 &lt;= 4) and
409 (($number mod 100 &lt; 10) or ($number mod 100 &gt;= 20))">
410 <xsl:text>1</xsl:text>
411 </xsl:when>
412 <xsl:otherwise>
413 <xsl:text>2</xsl:text>
414 </xsl:otherwise>
415 </xsl:choose>
416 </xsl:when>
417
418 <!-- == cy == -->
419 <xsl:when test="starts-with($normlang, 'cy-')">
420 <xsl:choose>
421 <xsl:when test="$number != 2">
422 <xsl:text>0</xsl:text>
423 </xsl:when>
424 <xsl:otherwise>
425 <xsl:text>1</xsl:text>
426 </xsl:otherwise>
427 </xsl:choose>
428 </xsl:when>
429
430 <!-- == fa hu ja ko th tr vi zh == -->
431 <xsl:when test="starts-with($normlang, 'ja-') or starts-with($normlang, 'ko-') or
432 starts-with($normlang, 'th-') or starts-with($normlang, 'tr-') or
433 starts-with($normlang, 'vi-') or starts-with($normlang, 'zh-') ">
434 <xsl:text>0</xsl:text>
435 </xsl:when>
436
437 <!-- == fr nso wa == -->
438 <xsl:when test="starts-with($normlang, 'fr-') or starts-with($normlang, 'nso-') or
439 starts-with($normlang, 'wa-') ">
440 <xsl:choose>
441 <xsl:when test="$number &gt; 1">
442 <xsl:text>1</xsl:text>
443 </xsl:when>
444 <xsl:otherwise>
445 <xsl:text>0</xsl:text>
446 </xsl:otherwise>
447 </xsl:choose>
448 </xsl:when>
449
450 <!-- == ga == -->
451 <xsl:when test="starts-with($normlang, 'ga-')">
452 <xsl:choose>
453 <xsl:when test="$number = 1">
454 <xsl:text>0</xsl:text>
455 </xsl:when>
456 <xsl:when test="$number = 2">
457 <xsl:text>1</xsl:text>
458 </xsl:when>
459 <xsl:otherwise>
460 <xsl:text>2</xsl:text>
461 </xsl:otherwise>
462 </xsl:choose>
463 </xsl:when>
464
465 <!-- == sk == -->
466 <xsl:when test="starts-with($normlang, 'sk-')">
467 <xsl:choose>
468 <xsl:when test="$number = 1">
469 <xsl:text>0</xsl:text>
470 </xsl:when>
471 <xsl:when test="($number &gt;= 2) and ($number &lt;= 4)">
472 <xsl:text>1</xsl:text>
473 </xsl:when>
474 <xsl:otherwise>
475 <xsl:text>2</xsl:text>
476 </xsl:otherwise>
477 </xsl:choose>
478 </xsl:when>
479
480 <!-- == sl == -->
481 <xsl:when test="starts-with($normlang, 'sl-')">
482 <xsl:choose>
483 <xsl:when test="$number mod 100 = 1">
484 <xsl:text>0</xsl:text>
485 </xsl:when>
486 <xsl:when test="$number mod 100 = 2">
487 <xsl:text>1</xsl:text>
488 </xsl:when>
489 <xsl:when test="($number mod 100 = 3) or ($number mod 100 = 4)">
490 <xsl:text>2</xsl:text>
491 </xsl:when>
492 <xsl:otherwise>
493 <xsl:text>3</xsl:text>
494 </xsl:otherwise>
495 </xsl:choose>
496 </xsl:when>
497
498 <!-- == C == -->
499 <xsl:otherwise>
500 <xsl:choose>
501 <xsl:when test="$number = 1">
502 <xsl:text>0</xsl:text>
503 </xsl:when>
504 <xsl:otherwise>
505 <xsl:text>1</xsl:text>
506 </xsl:otherwise>
507 </xsl:choose>
508 </xsl:otherwise>
509 </xsl:choose>
510 </xsl:template>
511
512
513 <!--**==========================================================================
514 l10n.direction
515 Determine the text direction for a language.
516 @revision[version=42 date=2021-10-30 status=final]
517
518 [xsl:params]
519 $node: The node to find the direction for.
520 $lang: The locale to use to determine the text direction.
521
522 This template returns the text direction for the language $lang. If $lang is
523 not provided, it looks for the nearest node to $node with a locale attribute,
524 either `xml:lang` or `lang`.
525
526 This template returns `"ltr"` for left-to-right languages and `"rtl"` for
527 right-to-left languages.
528
529 This template calls {l10n.gettext} with the string `default:LTR` in the domain
530 `yelp-xsl`. The language is right-to-left if the string `default:RTL` is
531 returned. Otherwise, it is left-to-right. (This particular string is used to
532 match the string used in GTK+, enabling translation memory.)
533
534 [note .plain]
535 The $node parameter was added in version 42, and the default value of the
536 $lang parameter was changed accordingly.
537 -->
538 <xsl:template name="l10n.direction">
539 <xsl:param name="node" select="."/>
540 <xsl:param name="lang">
541 <xsl:choose>
542 <xsl:when test="$node/ancestor-or-self::*[@xml:lang]">
543 <xsl:value-of select="$node/ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
544 </xsl:when>
545 <xsl:when test="$node/ancestor-or-self::*[@lang]">
546 <xsl:value-of select="$node/ancestor-or-self::*[@lang][1]/@xml:lang"/>
547 </xsl:when>
548 <xsl:otherwise>
549 <xsl:value-of select="$l10n.locale"/>
550 </xsl:otherwise>
551 </xsl:choose>
552 </xsl:param>
553 <xsl:variable name="direction">
554 <xsl:for-each select="/*">
555 <xsl:call-template name="l10n.gettext">
556 <xsl:with-param name="msgid" select="'default:LTR'"/>
557 <xsl:with-param name="lang" select="$lang"/>
558 </xsl:call-template>
559 </xsl:for-each>
560 </xsl:variable>
561 <xsl:choose>
562 <xsl:when test="$direction = 'default:RTL'">
563 <xsl:text>rtl</xsl:text>
564 </xsl:when>
565 <xsl:otherwise>
566 <xsl:text>ltr</xsl:text>
567 </xsl:otherwise>
568 </xsl:choose>
569 </xsl:template>
570
571
572 <!--**==========================================================================
573 l10n.align.start
574 Determine the start alignment.
575 @revision[version=3.18 date=2015-07-27 status=final]
576
577 [xsl:params]
578 $direction: The text direction.
579
580 This template returns the string `left` for left-to-right languages and the
581 string `right` for right-to-left languages. The result is suitable for
582 substituting in CSS rules that are direction-dependent. If you do not pass
583 the $direction parameter, it defaults to calling {l10n.direction} using
584 the default locale defined in {l10n.locale}.
585 -->
586 <xsl:template name="l10n.align.start">
587 <xsl:param name="direction">
588 <xsl:call-template name="l10n.direction"/>
589 </xsl:param>
590 <xsl:choose>
591 <xsl:when test="$direction = 'rtl'">
592 <xsl:text>right</xsl:text>
593 </xsl:when>
594 <xsl:otherwise>
595 <xsl:text>left</xsl:text>
596 </xsl:otherwise>
597 </xsl:choose>
598 </xsl:template>
599
600
601 <!--**==========================================================================
602 l10n.align.end
603 Determine the end alignment.
604 @revision[version=3.18 date=2015-07-27 status=final]
605
606 [xsl:params]
607 $direction: The text direction.
608
609 This template returns the string `right` for left-to-right languages and the
610 string `left` for right-to-left languages. The result is suitable for
611 substituting in CSS rules that are direction-dependent. If you do not pass
612 the $direction parameter, it defaults to calling {l10n.direction} using
613 the default locale defined in {l10n.locale}.
614 -->
615 <xsl:template name="l10n.align.end">
616 <xsl:param name="direction">
617 <xsl:call-template name="l10n.direction"/>
618 </xsl:param>
619 <xsl:choose>
620 <xsl:when test="$direction = 'rtl'">
621 <xsl:text>left</xsl:text>
622 </xsl:when>
623 <xsl:otherwise>
624 <xsl:text>right</xsl:text>
625 </xsl:otherwise>
626 </xsl:choose>
627 </xsl:template>
628
629
630 <!--%%==========================================================================
631 l10n.format.mode
632 Process format strings from {l10n.gettext}.
633 @revision[version=3.18 date=2015-08-13 status=final]
634
635 [xsl:params]
636 $node: The node being processed in the original document.
637 $string: String content to use for certain message format nodes.
638
639 This mode is called by {l10n.gettext} when its `format` parameter is set to
640 true. It is applied to the elements and text children of the translated message
641 that {l10n.gettext} finds. This allows you to insert content in format strings,
642 rather than concatenating multiple translations to create a translated message.
643
644 By default, this stylesheet provides matching templates in this mode for the
645 elements `node` and `string`. The template for `node` applies templates with
646 no mode to the $node parameter passed to {l10n.gettext}. The template for
647 `string` copies the text in the $string parameter passed to {l10n.gettext}.
648 Both parameters are passed to templates in this mode. Templates matching this
649 mode should pass those parameters to child content if they process child
650 content in {l10n.format.mode}.
651
652 To use format strings in your own translations, use elements with names of
653 your choosing in your message. You can use the `node` and `string` elements
654 without further implementation, if they fit your needs. Otherwise, take care
655 to use element names that are unlikely to conflict with other templates using
656 this mode.
657 -->
658 <xsl:template mode="l10n.format.mode" match="*">
659 <xsl:param name="node"/>
660 <xsl:apply-templates mode="l10n.format.mode">
661 <xsl:with-param name="node" select="$node"/>
662 </xsl:apply-templates>
663 </xsl:template>
664
665 <!-- = l10n.format.mode % msg:node = -->
666 <xsl:template mode="l10n.format.mode" match="msg:node">
667 <xsl:param name="node"/>
668 <xsl:apply-templates select="$node/node()"/>
669 </xsl:template>
670
671 <!-- = l10n.format.mode % msg:string = -->
672 <xsl:template mode="l10n.format.mode" match="msg:string">
673 <xsl:param name="string"/>
674 <xsl:value-of select="$string"/>
675 </xsl:template>
676
677 </xsl:stylesheet>