source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/l10n.xsl@ dda2263

clfs-3.0.0-systemd systemd
Last change on this file since dda2263 was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 15.2 KB
Line 
1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
4 exclude-result-prefixes="l"
5 version='1.0'>
6
7<!-- ********************************************************************
8 $Id$
9 ********************************************************************
10
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://docbook.sf.net/release/xsl/current/ for
13 copyright and other information.
14
15 This file contains localization templates (for internationalization)
16 ******************************************************************** -->
17
18<xsl:param name="l10n.xml" select="document('../common/l10n.xml')"/>
19<xsl:param name="local.l10n.xml" select="document('')"/>
20
21<xsl:template name="l10n.language">
22 <xsl:param name="target" select="."/>
23 <xsl:param name="xref-context" select="false()"/>
24
25 <xsl:variable name="mc-language">
26 <xsl:choose>
27 <xsl:when test="$l10n.gentext.language != ''">
28 <xsl:value-of select="$l10n.gentext.language"/>
29 </xsl:when>
30
31 <xsl:when test="$xref-context or $l10n.gentext.use.xref.language != 0">
32 <!-- can't do this one step: attributes are unordered! -->
33 <xsl:variable name="lang-scope"
34 select="$target/ancestor-or-self::*
35 [@lang or @xml:lang][1]"/>
36 <xsl:variable name="lang-attr"
37 select="($lang-scope/@lang | $lang-scope/@xml:lang)[1]"/>
38 <xsl:choose>
39 <xsl:when test="string($lang-attr) = ''">
40 <xsl:value-of select="$l10n.gentext.default.language"/>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:value-of select="$lang-attr"/>
44 </xsl:otherwise>
45 </xsl:choose>
46 </xsl:when>
47
48 <xsl:otherwise>
49 <!-- can't do this one step: attributes are unordered! -->
50 <xsl:variable name="lang-scope"
51 select="$target/ancestor-or-self::*
52 [@lang or @xml:lang][1]"/>
53 <xsl:variable name="lang-attr"
54 select="($lang-scope/@lang | $lang-scope/@xml:lang)[1]"/>
55
56 <xsl:choose>
57 <xsl:when test="string($lang-attr) = ''">
58 <xsl:value-of select="$l10n.gentext.default.language"/>
59 </xsl:when>
60 <xsl:otherwise>
61 <xsl:value-of select="$lang-attr"/>
62 </xsl:otherwise>
63 </xsl:choose>
64 </xsl:otherwise>
65 </xsl:choose>
66 </xsl:variable>
67
68 <xsl:variable name="language" select="translate($mc-language,
69 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
70 'abcdefghijklmnopqrstuvwxyz')"/>
71
72 <xsl:variable name="adjusted.language">
73 <xsl:choose>
74 <xsl:when test="contains($language,'-')">
75 <xsl:value-of select="substring-before($language,'-')"/>
76 <xsl:text>_</xsl:text>
77 <xsl:value-of select="substring-after($language,'-')"/>
78 </xsl:when>
79 <xsl:otherwise>
80 <xsl:value-of select="$language"/>
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:variable>
84
85 <xsl:choose>
86 <xsl:when test="$l10n.xml/l:i18n/l:l10n[@language=$adjusted.language]">
87 <xsl:value-of select="$adjusted.language"/>
88 </xsl:when>
89 <!-- try just the lang code without country -->
90 <xsl:when test="$l10n.xml/l:i18n/l:l10n[@language=substring-before($adjusted.language,'_')]">
91 <xsl:value-of select="substring-before($adjusted.language,'_')"/>
92 </xsl:when>
93 <!-- or use the default -->
94 <xsl:otherwise>
95 <xsl:message>
96 <xsl:text>No localization exists for "</xsl:text>
97 <xsl:value-of select="$adjusted.language"/>
98 <xsl:text>" or "</xsl:text>
99 <xsl:value-of select="substring-before($adjusted.language,'_')"/>
100 <xsl:text>". Using default "</xsl:text>
101 <xsl:value-of select="$l10n.gentext.default.language"/>
102 <xsl:text>".</xsl:text>
103 </xsl:message>
104 <xsl:value-of select="$l10n.gentext.default.language"/>
105 </xsl:otherwise>
106 </xsl:choose>
107</xsl:template>
108
109<xsl:template name="language.attribute">
110 <xsl:param name="node" select="."/>
111
112 <xsl:variable name="language">
113 <xsl:choose>
114 <xsl:when test="$l10n.gentext.language != ''">
115 <xsl:value-of select="$l10n.gentext.language"/>
116 </xsl:when>
117
118 <xsl:otherwise>
119 <!-- can't do this one step: attributes are unordered! -->
120 <xsl:variable name="lang-scope"
121 select="$node/ancestor-or-self::*
122 [@lang or @xml:lang][1]"/>
123 <xsl:variable name="lang-attr"
124 select="($lang-scope/@lang | $lang-scope/@xml:lang)[1]"/>
125
126 <xsl:choose>
127 <xsl:when test="string($lang-attr) = ''">
128 <xsl:value-of select="$l10n.gentext.default.language"/>
129 </xsl:when>
130 <xsl:otherwise>
131 <xsl:value-of select="$lang-attr"/>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:otherwise>
135 </xsl:choose>
136 </xsl:variable>
137
138 <xsl:if test="$language != ''">
139 <xsl:attribute name="lang">
140 <xsl:choose>
141 <xsl:when test="$l10n.lang.value.rfc.compliant != 0">
142 <xsl:value-of select="translate($language, '_', '-')"/>
143 </xsl:when>
144 <xsl:otherwise>
145 <xsl:value-of select="$language"/>
146 </xsl:otherwise>
147 </xsl:choose>
148 </xsl:attribute>
149 </xsl:if>
150
151 <!-- FIXME: This is sort of hack, but it was the easiest way to add at least partial support for dir attribute -->
152 <xsl:copy-of select="ancestor-or-self::*[@dir][1]/@dir"/>
153</xsl:template>
154
155<xsl:template name="gentext">
156 <xsl:param name="key" select="local-name(.)"/>
157 <xsl:param name="lang">
158 <xsl:call-template name="l10n.language"/>
159 </xsl:param>
160
161 <xsl:variable name="local.l10n.gentext"
162 select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
163
164 <xsl:variable name="l10n.gentext"
165 select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
166
167 <xsl:choose>
168 <xsl:when test="$local.l10n.gentext">
169 <xsl:value-of select="$local.l10n.gentext/@text"/>
170 </xsl:when>
171 <xsl:when test="$l10n.gentext">
172 <xsl:value-of select="$l10n.gentext/@text"/>
173 </xsl:when>
174 <xsl:otherwise>
175 <xsl:message>
176 <xsl:text>No "</xsl:text>
177 <xsl:value-of select="$lang"/>
178 <xsl:text>" localization of "</xsl:text>
179 <xsl:value-of select="$key"/>
180 <xsl:text>" exists</xsl:text>
181 <xsl:choose>
182 <xsl:when test="$lang = 'en'">
183 <xsl:text>.</xsl:text>
184 </xsl:when>
185 <xsl:otherwise>
186 <xsl:text>; using "en".</xsl:text>
187 </xsl:otherwise>
188 </xsl:choose>
189 </xsl:message>
190
191 <xsl:value-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:gentext[@key=$key])[1]/@text"/>
192 </xsl:otherwise>
193 </xsl:choose>
194</xsl:template>
195
196<xsl:template name="gentext.element.name">
197 <xsl:param name="element.name" select="local-name(.)"/>
198 <xsl:param name="lang">
199 <xsl:call-template name="l10n.language"/>
200 </xsl:param>
201
202 <xsl:call-template name="gentext">
203 <xsl:with-param name="key" select="$element.name"/>
204 <xsl:with-param name="lang" select="$lang"/>
205 </xsl:call-template>
206</xsl:template>
207
208<xsl:template name="gentext.space">
209 <xsl:text> </xsl:text>
210</xsl:template>
211
212<xsl:template name="gentext.edited.by">
213 <xsl:call-template name="gentext">
214 <xsl:with-param name="key" select="'Editedby'"/>
215 </xsl:call-template>
216</xsl:template>
217
218<xsl:template name="gentext.by">
219 <xsl:call-template name="gentext">
220 <xsl:with-param name="key" select="'by'"/>
221 </xsl:call-template>
222</xsl:template>
223
224<xsl:template name="gentext.dingbat">
225 <xsl:param name="dingbat">bullet</xsl:param>
226 <xsl:param name="lang">
227 <xsl:call-template name="l10n.language"/>
228 </xsl:param>
229
230 <xsl:variable name="local.l10n.dingbat"
231 select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
232
233 <xsl:variable name="l10n.dingbat"
234 select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
235
236 <xsl:choose>
237 <xsl:when test="$local.l10n.dingbat">
238 <xsl:value-of select="$local.l10n.dingbat/@text"/>
239 </xsl:when>
240 <xsl:when test="$l10n.dingbat">
241 <xsl:value-of select="$l10n.dingbat/@text"/>
242 </xsl:when>
243 <xsl:otherwise>
244 <xsl:message>
245 <xsl:text>No "</xsl:text>
246 <xsl:value-of select="$lang"/>
247 <xsl:text>" localization of dingbat </xsl:text>
248 <xsl:value-of select="$dingbat"/>
249 <xsl:text> exists; using "en".</xsl:text>
250 </xsl:message>
251
252 <xsl:value-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:dingbat[@key=$dingbat])[1]/@text"/>
253 </xsl:otherwise>
254 </xsl:choose>
255</xsl:template>
256
257<xsl:template name="gentext.startquote">
258 <xsl:call-template name="gentext.dingbat">
259 <xsl:with-param name="dingbat">startquote</xsl:with-param>
260 </xsl:call-template>
261</xsl:template>
262
263<xsl:template name="gentext.endquote">
264 <xsl:call-template name="gentext.dingbat">
265 <xsl:with-param name="dingbat">endquote</xsl:with-param>
266 </xsl:call-template>
267</xsl:template>
268
269<xsl:template name="gentext.nestedstartquote">
270 <xsl:call-template name="gentext.dingbat">
271 <xsl:with-param name="dingbat">nestedstartquote</xsl:with-param>
272 </xsl:call-template>
273</xsl:template>
274
275<xsl:template name="gentext.nestedendquote">
276 <xsl:call-template name="gentext.dingbat">
277 <xsl:with-param name="dingbat">nestedendquote</xsl:with-param>
278 </xsl:call-template>
279</xsl:template>
280
281<xsl:template name="gentext.nav.prev">
282 <xsl:call-template name="gentext">
283 <xsl:with-param name="key" select="'nav-prev'"/>
284 </xsl:call-template>
285</xsl:template>
286
287<xsl:template name="gentext.nav.next">
288 <xsl:call-template name="gentext">
289 <xsl:with-param name="key" select="'nav-next'"/>
290 </xsl:call-template>
291</xsl:template>
292
293<xsl:template name="gentext.nav.home">
294 <xsl:call-template name="gentext">
295 <xsl:with-param name="key" select="'nav-home'"/>
296 </xsl:call-template>
297</xsl:template>
298
299<xsl:template name="gentext.nav.up">
300 <xsl:call-template name="gentext">
301 <xsl:with-param name="key" select="'nav-up'"/>
302 </xsl:call-template>
303</xsl:template>
304
305<!-- ============================================================ -->
306
307<xsl:template name="gentext.template">
308 <xsl:param name="context" select="'default'"/>
309 <xsl:param name="name" select="'default'"/>
310 <xsl:param name="origname" select="$name"/>
311 <xsl:param name="purpose"/>
312 <xsl:param name="xrefstyle"/>
313 <xsl:param name="referrer"/>
314 <xsl:param name="lang">
315 <xsl:call-template name="l10n.language"/>
316 </xsl:param>
317 <xsl:param name="verbose" select="1"/>
318
319 <xsl:variable name="local.localization.node"
320 select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang])[1]"/>
321
322 <xsl:variable name="localization.node"
323 select="($l10n.xml/l:i18n/l:l10n[@language=$lang])[1]"/>
324
325 <xsl:if test="count($localization.node) = 0
326 and count($local.localization.node) = 0
327 and $verbose != 0">
328 <xsl:message>
329 <xsl:text>No "</xsl:text>
330 <xsl:value-of select="$lang"/>
331 <xsl:text>" localization exists.</xsl:text>
332 </xsl:message>
333 </xsl:if>
334
335 <xsl:variable name="local.context.node"
336 select="$local.localization.node/l:context[@name=$context]"/>
337
338 <xsl:variable name="context.node"
339 select="$localization.node/l:context[@name=$context]"/>
340
341 <xsl:if test="count($context.node) = 0
342 and count($local.context.node) = 0
343 and $verbose != 0">
344 <xsl:message>
345 <xsl:text>No context named "</xsl:text>
346 <xsl:value-of select="$context"/>
347 <xsl:text>" exists in the "</xsl:text>
348 <xsl:value-of select="$lang"/>
349 <xsl:text>" localization.</xsl:text>
350 </xsl:message>
351 </xsl:if>
352
353 <xsl:variable name="local.template.node"
354 select="($local.context.node/l:template[@name=$name
355 and @style
356 and @style=$xrefstyle]
357 |$local.context.node/l:template[@name=$name
358 and not(@style)])[1]"/>
359
360 <xsl:variable name="template.node"
361 select="($context.node/l:template[@name=$name
362 and @style
363 and @style=$xrefstyle]
364 |$context.node/l:template[@name=$name
365 and not(@style)])[1]"/>
366
367 <xsl:choose>
368 <xsl:when test="$local.template.node/@text">
369 <xsl:value-of select="$local.template.node/@text"/>
370 </xsl:when>
371 <xsl:when test="$template.node/@text">
372 <xsl:value-of select="$template.node/@text"/>
373 </xsl:when>
374 <xsl:otherwise>
375 <xsl:choose>
376 <xsl:when test="contains($name, '/')">
377 <xsl:call-template name="gentext.template">
378 <xsl:with-param name="context" select="$context"/>
379 <xsl:with-param name="name" select="substring-after($name, '/')"/>
380 <xsl:with-param name="origname" select="$origname"/>
381 <xsl:with-param name="purpose" select="$purpose"/>
382 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
383 <xsl:with-param name="referrer" select="$referrer"/>
384 <xsl:with-param name="lang" select="$lang"/>
385 <xsl:with-param name="verbose" select="$verbose"/>
386 </xsl:call-template>
387 </xsl:when>
388 <xsl:when test="$verbose = 0">
389 <!-- silence -->
390 </xsl:when>
391 <xsl:otherwise>
392 <xsl:message>
393 <xsl:text>No template for "</xsl:text>
394 <xsl:value-of select="$origname"/>
395 <xsl:text>" (or any of its leaves) exists
396in the context named "</xsl:text>
397 <xsl:value-of select="$context"/>
398 <xsl:text>" in the "</xsl:text>
399 <xsl:value-of select="$lang"/>
400 <xsl:text>" localization.</xsl:text>
401 </xsl:message>
402 </xsl:otherwise>
403 </xsl:choose>
404 </xsl:otherwise>
405 </xsl:choose>
406</xsl:template>
407
408<!-- silently test if a gentext template exists -->
409
410<xsl:template name="gentext.template.exists">
411 <xsl:param name="context" select="'default'"/>
412 <xsl:param name="name" select="'default'"/>
413 <xsl:param name="origname" select="$name"/>
414 <xsl:param name="purpose"/>
415 <xsl:param name="xrefstyle"/>
416 <xsl:param name="referrer"/>
417 <xsl:param name="lang">
418 <xsl:call-template name="l10n.language"/>
419 </xsl:param>
420
421 <xsl:variable name="template">
422 <xsl:call-template name="gentext.template">
423 <xsl:with-param name="context" select="$context"/>
424 <xsl:with-param name="name" select="$name"/>
425 <xsl:with-param name="origname" select="$origname"/>
426 <xsl:with-param name="purpose" select="$purpose"/>
427 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
428 <xsl:with-param name="referrer" select="$referrer"/>
429 <xsl:with-param name="lang" select="$lang"/>
430 <xsl:with-param name="verbose" select="0"/>
431 </xsl:call-template>
432 </xsl:variable>
433
434 <xsl:choose>
435 <xsl:when test="string-length($template) != 0">1</xsl:when>
436 <xsl:otherwise>0</xsl:otherwise>
437 </xsl:choose>
438</xsl:template>
439
440</xsl:stylesheet>
441
Note: See TracBrowser for help on using the repository browser.