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"
7 <!-- ********************************************************************
8 $Id: l10n.xsl,v 1.1 2007/03/10 05:14:55 scott Exp $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13 and other information.
15 This file contains localization templates (for internationalization)
16 ******************************************************************** -->
18 <xsl:param name=
"l10n.xml" select=
"document('../common/l10n.xml')"/>
19 <xsl:param name=
"local.l10n.xml" select=
"document('')"/>
21 <xsl:template name=
"l10n.language">
22 <xsl:param name=
"target" select=
"."/>
23 <xsl:param name=
"xref-context" select=
"false()"/>
25 <xsl:variable name=
"mc-language">
27 <xsl:when test=
"$l10n.gentext.language != ''">
28 <xsl:value-of select=
"$l10n.gentext.language"/>
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]"/>
39 <xsl:when test=
"string($lang-attr) = ''">
40 <xsl:value-of select=
"$l10n.gentext.default.language"/>
43 <xsl:value-of select=
"$lang-attr"/>
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]"/>
57 <xsl:when test=
"string($lang-attr) = ''">
58 <xsl:value-of select=
"$l10n.gentext.default.language"/>
61 <xsl:value-of select=
"$lang-attr"/>
68 <xsl:variable name=
"language" select=
"translate($mc-language,
69 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
70 'abcdefghijklmnopqrstuvwxyz')"/>
72 <xsl:variable name=
"adjusted.language">
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,'-')"/>
80 <xsl:value-of select=
"$language"/>
86 <xsl:when test=
"$l10n.xml/l:i18n/l:l10n[@language=$adjusted.language]">
87 <xsl:value-of select=
"$adjusted.language"/>
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,'_')"/>
93 <!-- or use the default -->
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>
104 <xsl:value-of select=
"$l10n.gentext.default.language"/>
109 <xsl:template name=
"language.attribute">
110 <xsl:param name=
"node" select=
"."/>
112 <xsl:variable name=
"language">
114 <xsl:when test=
"$l10n.gentext.language != ''">
115 <xsl:value-of select=
"$l10n.gentext.language"/>
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]"/>
127 <xsl:when test=
"string($lang-attr) = ''">
128 <xsl:value-of select=
"$l10n.gentext.default.language"/>
131 <xsl:value-of select=
"$lang-attr"/>
138 <xsl:if test=
"$language != ''">
139 <xsl:attribute name=
"lang">
141 <xsl:when test=
"$l10n.lang.value.rfc.compliant != 0">
142 <xsl:value-of select=
"translate($language, '_', '-')"/>
145 <xsl:value-of select=
"$language"/>
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"/>
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"/>
161 <xsl:variable name=
"local.l10n.gentext"
162 select=
"($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
164 <xsl:variable name=
"l10n.gentext"
165 select=
"($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
168 <xsl:when test=
"$local.l10n.gentext">
169 <xsl:value-of select=
"$local.l10n.gentext/@text"/>
171 <xsl:when test=
"$l10n.gentext">
172 <xsl:value-of select=
"$l10n.gentext/@text"/>
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>
182 <xsl:when test=
"$lang = 'en'">
183 <xsl:text>.
</xsl:text>
186 <xsl:text>; using
"en".
</xsl:text>
191 <xsl:value-of select=
"($l10n.xml/l:i18n/l:l10n[@language='en']/l:gentext[@key=$key])[1]/@text"/>
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"/>
202 <xsl:call-template name=
"gentext">
203 <xsl:with-param name=
"key" select=
"$element.name"/>
204 <xsl:with-param name=
"lang" select=
"$lang"/>
208 <xsl:template name=
"gentext.space">
209 <xsl:text> </xsl:text>
212 <xsl:template name=
"gentext.edited.by">
213 <xsl:call-template name=
"gentext">
214 <xsl:with-param name=
"key" select=
"'Editedby'"/>
218 <xsl:template name=
"gentext.by">
219 <xsl:call-template name=
"gentext">
220 <xsl:with-param name=
"key" select=
"'by'"/>
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"/>
230 <xsl:variable name=
"local.l10n.dingbat"
231 select=
"($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
233 <xsl:variable name=
"l10n.dingbat"
234 select=
"($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
237 <xsl:when test=
"$local.l10n.dingbat">
238 <xsl:value-of select=
"$local.l10n.dingbat/@text"/>
240 <xsl:when test=
"$l10n.dingbat">
241 <xsl:value-of select=
"$l10n.dingbat/@text"/>
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>
252 <xsl:value-of select=
"($l10n.xml/l:i18n/l:l10n[@language='en']/l:dingbat[@key=$dingbat])[1]/@text"/>
257 <xsl:template name=
"gentext.startquote">
258 <xsl:call-template name=
"gentext.dingbat">
259 <xsl:with-param name=
"dingbat">startquote
</xsl:with-param>
263 <xsl:template name=
"gentext.endquote">
264 <xsl:call-template name=
"gentext.dingbat">
265 <xsl:with-param name=
"dingbat">endquote
</xsl:with-param>
269 <xsl:template name=
"gentext.nestedstartquote">
270 <xsl:call-template name=
"gentext.dingbat">
271 <xsl:with-param name=
"dingbat">nestedstartquote
</xsl:with-param>
275 <xsl:template name=
"gentext.nestedendquote">
276 <xsl:call-template name=
"gentext.dingbat">
277 <xsl:with-param name=
"dingbat">nestedendquote
</xsl:with-param>
281 <xsl:template name=
"gentext.nav.prev">
282 <xsl:call-template name=
"gentext">
283 <xsl:with-param name=
"key" select=
"'nav-prev'"/>
287 <xsl:template name=
"gentext.nav.next">
288 <xsl:call-template name=
"gentext">
289 <xsl:with-param name=
"key" select=
"'nav-next'"/>
293 <xsl:template name=
"gentext.nav.home">
294 <xsl:call-template name=
"gentext">
295 <xsl:with-param name=
"key" select=
"'nav-home'"/>
299 <xsl:template name=
"gentext.nav.up">
300 <xsl:call-template name=
"gentext">
301 <xsl:with-param name=
"key" select=
"'nav-up'"/>
305 <!-- ============================================================ -->
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"/>
317 <xsl:param name=
"verbose" select=
"1"/>
319 <xsl:variable name=
"local.localization.node"
320 select=
"($local.l10n.xml//l:i18n/l:l10n[@language=$lang])[1]"/>
322 <xsl:variable name=
"localization.node"
323 select=
"($l10n.xml/l:i18n/l:l10n[@language=$lang])[1]"/>
325 <xsl:if test=
"count($localization.node) = 0
326 and count($local.localization.node) = 0
329 <xsl:text>No
"</xsl:text>
330 <xsl:value-of select="$lang
"/>
331 <xsl:text>" localization exists.
</xsl:text>
335 <xsl:variable name=
"local.context.node"
336 select=
"$local.localization.node/l:context[@name=$context]"/>
338 <xsl:variable name=
"context.node"
339 select=
"$localization.node/l:context[@name=$context]"/>
341 <xsl:if test=
"count($context.node) = 0
342 and count($local.context.node) = 0
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>
353 <xsl:variable name=
"local.template.node"
354 select=
"($local.context.node/l:template[@name=$name
356 and @style=$xrefstyle]
357 |$local.context.node/l:template[@name=$name
358 and not(@style)])[1]"/>
360 <xsl:variable name=
"template.node"
361 select=
"($context.node/l:template[@name=$name
363 and @style=$xrefstyle]
364 |$context.node/l:template[@name=$name
365 and not(@style)])[1]"/>
368 <xsl:when test=
"$local.template.node/@text">
369 <xsl:value-of select=
"$local.template.node/@text"/>
371 <xsl:when test=
"$template.node/@text">
372 <xsl:value-of select=
"$template.node/@text"/>
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"/>
388 <xsl:when test=
"$verbose = 0">
393 <xsl:text>No template for
"</xsl:text>
394 <xsl:value-of select="$origname
"/>
395 <xsl:text>" (or any of its leaves) exists
396 in 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>
408 <!-- silently test if a gentext template exists -->
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"/>
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"/>
435 <xsl:when test=
"string-length($template) != 0">1</xsl:when>
436 <xsl:otherwise>0</xsl:otherwise>