Project

General

Profile

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: l10n.xsl 8001 2008-04-15 03:19:23Z abdelazer $
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="l10.language.name">
110
  <xsl:param name="lang">
111
    <xsl:call-template name="l10n.language"/>
112
  </xsl:param>
113
  <xsl:value-of
114
    select="$l10n.xml/l:i18n/l:l10n[@language=$lang]/@english-language-name"/>
115
</xsl:template>
116

    
117
<xsl:template name="language.attribute">
118
  <xsl:param name="node" select="."/>
119

    
120
  <xsl:variable name="language">
121
    <xsl:choose>
122
      <xsl:when test="$l10n.gentext.language != ''">
123
        <xsl:value-of select="$l10n.gentext.language"/>
124
      </xsl:when>
125

    
126
      <xsl:otherwise>
127
        <!-- can't do this one step: attributes are unordered! -->
128
        <xsl:variable name="lang-scope"
129
                      select="$node/ancestor-or-self::*
130
                              [@lang or @xml:lang][1]"/>
131
        <xsl:variable name="lang-attr"
132
                      select="($lang-scope/@lang | $lang-scope/@xml:lang)[1]"/>
133

    
134
        <xsl:choose>
135
          <xsl:when test="string($lang-attr) = ''">
136
            <xsl:value-of select="$l10n.gentext.default.language"/>
137
          </xsl:when>
138
          <xsl:otherwise>
139
            <xsl:value-of select="$lang-attr"/>
140
          </xsl:otherwise>
141
        </xsl:choose>
142
      </xsl:otherwise>
143
    </xsl:choose>
144
  </xsl:variable>
145

    
146
  <xsl:if test="$language != ''">
147
    <xsl:attribute name="lang">
148
      <xsl:choose>
149
        <xsl:when test="$l10n.lang.value.rfc.compliant != 0">
150
          <xsl:value-of select="translate($language, '_', '-')"/>
151
        </xsl:when>
152
        <xsl:otherwise>
153
          <xsl:value-of select="$language"/>
154
        </xsl:otherwise>
155
      </xsl:choose>
156
    </xsl:attribute>
157
  </xsl:if>
158

    
159
  <!-- FIXME: This is sort of hack, but it was the easiest way to add at least partial support for dir attribute -->
160
  <xsl:copy-of select="ancestor-or-self::*[@dir][1]/@dir"/>
161
</xsl:template>
162

    
163
<!-- Duplication of language.attribute template to allow for xml:lang attribute
164
     creation for XHTML 1.1 and epub target -->
165
<xsl:template name="xml.language.attribute">
166
  <xsl:param name="node" select="."/>
167

    
168
  <xsl:variable name="language">
169
    <xsl:choose>
170
      <xsl:when test="$l10n.gentext.language != ''">
171
        <xsl:value-of select="$l10n.gentext.language"/>
172
      </xsl:when>
173

    
174
      <xsl:otherwise>
175
        <!-- can't do this one step: attributes are unordered! -->
176
        <xsl:variable name="lang-scope"
177
                      select="$node/ancestor-or-self::*
178
                              [@lang or @xml:lang][1]"/>
179
        <xsl:variable name="lang-attr"
180
                      select="($lang-scope/@lang | $lang-scope/@xml:lang)[1]"/>
181

    
182
        <xsl:choose>
183
          <xsl:when test="string($lang-attr) = ''">
184
            <xsl:value-of select="$l10n.gentext.default.language"/>
185
          </xsl:when>
186
          <xsl:otherwise>
187
            <xsl:value-of select="$lang-attr"/>
188
          </xsl:otherwise>
189
        </xsl:choose>
190
      </xsl:otherwise>
191
    </xsl:choose>
192
  </xsl:variable>
193

    
194
  <xsl:if test="$language != ''">
195
    <xsl:attribute name="xml:lang">
196
      <xsl:choose>
197
        <xsl:when test="$l10n.lang.value.rfc.compliant != 0">
198
          <xsl:value-of select="translate($language, '_', '-')"/>
199
        </xsl:when>
200
        <xsl:otherwise>
201
          <xsl:value-of select="$language"/>
202
        </xsl:otherwise>
203
      </xsl:choose>
204
    </xsl:attribute>
205
  </xsl:if>
206

    
207
  <!-- FIXME: This is sort of hack, but it was the easiest way to add at least partial support for dir attribute -->
208
  <xsl:copy-of select="ancestor-or-self::*[@dir][1]/@dir"/>
209
</xsl:template>
210

    
211
<xsl:template name="gentext">
212
  <xsl:param name="key" select="local-name(.)"/>
213
  <xsl:param name="lang">
214
    <xsl:call-template name="l10n.language"/>
215
  </xsl:param>
216

    
217
  <xsl:variable name="local.l10n.gentext"
218
                select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
219

    
220
  <xsl:variable name="l10n.gentext"
221
                select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:gentext[@key=$key])[1]"/>
222

    
223
  <xsl:choose>
224
    <xsl:when test="$local.l10n.gentext">
225
      <xsl:value-of select="$local.l10n.gentext/@text"/>
226
    </xsl:when>
227
    <xsl:when test="$l10n.gentext">
228
      <xsl:value-of select="$l10n.gentext/@text"/>
229
    </xsl:when>
230
    <xsl:otherwise>
231
      <xsl:message>
232
        <xsl:text>No "</xsl:text>
233
        <xsl:value-of select="$lang"/>
234
        <xsl:text>" localization of "</xsl:text>
235
        <xsl:value-of select="$key"/>
236
        <xsl:text>" exists</xsl:text>
237
        <xsl:choose>
238
          <xsl:when test="$lang = 'en'">
239
             <xsl:text>.</xsl:text>
240
          </xsl:when>
241
          <xsl:otherwise>
242
             <xsl:text>; using "en".</xsl:text>
243
          </xsl:otherwise>
244
        </xsl:choose>
245
      </xsl:message>
246

    
247
      <xsl:value-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:gentext[@key=$key])[1]/@text"/>
248
    </xsl:otherwise>
249
  </xsl:choose>
250
</xsl:template>
251

    
252
<xsl:template name="gentext.element.name">
253
  <xsl:param name="element.name" select="local-name(.)"/>
254
  <xsl:param name="lang">
255
    <xsl:call-template name="l10n.language"/>
256
  </xsl:param>
257

    
258
  <xsl:call-template name="gentext">
259
    <xsl:with-param name="key" select="$element.name"/>
260
    <xsl:with-param name="lang" select="$lang"/>
261
  </xsl:call-template>
262
</xsl:template>
263

    
264
<xsl:template name="gentext.space">
265
  <xsl:text> </xsl:text>
266
</xsl:template>
267

    
268
<xsl:template name="gentext.edited.by">
269
  <xsl:call-template name="gentext">
270
    <xsl:with-param name="key" select="'Editedby'"/>
271
  </xsl:call-template>
272
</xsl:template>
273

    
274
<xsl:template name="gentext.by">
275
  <xsl:call-template name="gentext">
276
    <xsl:with-param name="key" select="'by'"/>
277
  </xsl:call-template>
278
</xsl:template>
279

    
280
<xsl:template name="gentext.dingbat">
281
  <xsl:param name="dingbat">bullet</xsl:param>
282
  <xsl:param name="lang">
283
    <xsl:call-template name="l10n.language"/>
284
  </xsl:param>
285

    
286
  <xsl:variable name="local.l10n.dingbat"
287
                select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
288

    
289
  <xsl:variable name="l10n.dingbat"
290
                select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:dingbat[@key=$dingbat])[1]"/>
291

    
292
  <xsl:choose>
293
    <xsl:when test="$local.l10n.dingbat">
294
      <xsl:value-of select="$local.l10n.dingbat/@text"/>
295
    </xsl:when>
296
    <xsl:when test="$l10n.dingbat">
297
      <xsl:value-of select="$l10n.dingbat/@text"/>
298
    </xsl:when>
299
    <xsl:otherwise>
300
      <xsl:message>
301
        <xsl:text>No "</xsl:text>
302
        <xsl:value-of select="$lang"/>
303
        <xsl:text>" localization of dingbat </xsl:text>
304
        <xsl:value-of select="$dingbat"/>
305
        <xsl:text> exists; using "en".</xsl:text>
306
      </xsl:message>
307

    
308
      <xsl:value-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:dingbat[@key=$dingbat])[1]/@text"/>
309
    </xsl:otherwise>
310
  </xsl:choose>
311
</xsl:template>
312

    
313
<xsl:template name="gentext.startquote">
314
  <xsl:call-template name="gentext.dingbat">
315
    <xsl:with-param name="dingbat">startquote</xsl:with-param>
316
  </xsl:call-template>
317
</xsl:template>
318

    
319
<xsl:template name="gentext.endquote">
320
  <xsl:call-template name="gentext.dingbat">
321
    <xsl:with-param name="dingbat">endquote</xsl:with-param>
322
  </xsl:call-template>
323
</xsl:template>
324

    
325
<xsl:template name="gentext.nestedstartquote">
326
  <xsl:call-template name="gentext.dingbat">
327
    <xsl:with-param name="dingbat">nestedstartquote</xsl:with-param>
328
  </xsl:call-template>
329
</xsl:template>
330

    
331
<xsl:template name="gentext.nestedendquote">
332
  <xsl:call-template name="gentext.dingbat">
333
    <xsl:with-param name="dingbat">nestedendquote</xsl:with-param>
334
  </xsl:call-template>
335
</xsl:template>
336

    
337
<xsl:template name="gentext.nav.prev">
338
  <xsl:call-template name="gentext">
339
    <xsl:with-param name="key" select="'nav-prev'"/>
340
  </xsl:call-template>
341
</xsl:template>
342

    
343
<xsl:template name="gentext.nav.next">
344
  <xsl:call-template name="gentext">
345
    <xsl:with-param name="key" select="'nav-next'"/>
346
  </xsl:call-template>
347
</xsl:template>
348

    
349
<xsl:template name="gentext.nav.home">
350
  <xsl:call-template name="gentext">
351
    <xsl:with-param name="key" select="'nav-home'"/>
352
  </xsl:call-template>
353
</xsl:template>
354

    
355
<xsl:template name="gentext.nav.up">
356
  <xsl:call-template name="gentext">
357
    <xsl:with-param name="key" select="'nav-up'"/>
358
  </xsl:call-template>
359
</xsl:template>
360

    
361
<!-- ============================================================ -->
362

    
363
<xsl:template name="gentext.template">
364
  <xsl:param name="context" select="'default'"/>
365
  <xsl:param name="name" select="'default'"/>
366
  <xsl:param name="origname" select="$name"/>
367
  <xsl:param name="purpose"/>
368
  <xsl:param name="xrefstyle"/>
369
  <xsl:param name="referrer"/>
370
  <xsl:param name="lang">
371
    <xsl:call-template name="l10n.language"/>
372
  </xsl:param>
373
  <xsl:param name="verbose" select="1"/>
374

    
375
  <xsl:variable name="local.localization.node"
376
                select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang])[1]"/>
377

    
378
  <xsl:variable name="localization.node"
379
                select="($l10n.xml/l:i18n/l:l10n[@language=$lang])[1]"/>
380

    
381
  <xsl:if test="count($localization.node) = 0
382
                and count($local.localization.node) = 0
383
                and $verbose != 0">
384
    <xsl:message>
385
      <xsl:text>No "</xsl:text>
386
      <xsl:value-of select="$lang"/>
387
      <xsl:text>" localization exists.</xsl:text>
388
    </xsl:message>
389
  </xsl:if>
390

    
391
  <xsl:variable name="local.context.node"
392
                select="$local.localization.node/l:context[@name=$context]"/>
393

    
394
  <xsl:variable name="context.node"
395
                select="$localization.node/l:context[@name=$context]"/>
396

    
397
  <xsl:if test="count($context.node) = 0
398
                and count($local.context.node) = 0
399
                and $verbose != 0">
400
    <xsl:message>
401
      <xsl:text>No context named "</xsl:text>
402
      <xsl:value-of select="$context"/>
403
      <xsl:text>" exists in the "</xsl:text>
404
      <xsl:value-of select="$lang"/>
405
      <xsl:text>" localization.</xsl:text>
406
    </xsl:message>
407
  </xsl:if>
408

    
409
  <xsl:variable name="local.template.node"
410
                select="($local.context.node/l:template[@name=$name
411
                                                        and @style
412
                                                        and @style=$xrefstyle]
413
                        |$local.context.node/l:template[@name=$name
414
                                                        and not(@style)])[1]"/>
415

    
416
  <xsl:variable name="template.node"
417
                select="($context.node/l:template[@name=$name
418
                                                  and @style
419
                                                  and @style=$xrefstyle]
420
                        |$context.node/l:template[@name=$name
421
                                                  and not(@style)])[1]"/>
422

    
423
  <xsl:choose>
424
    <xsl:when test="$local.template.node/@text">
425
      <xsl:value-of select="$local.template.node/@text"/>
426
    </xsl:when>
427
    <xsl:when test="$template.node/@text">
428
      <xsl:value-of select="$template.node/@text"/>
429
    </xsl:when>
430
    <xsl:otherwise>
431
      <xsl:choose>
432
        <xsl:when test="contains($name, '/')">
433
          <xsl:call-template name="gentext.template">
434
            <xsl:with-param name="context" select="$context"/>
435
            <xsl:with-param name="name" select="substring-after($name, '/')"/>
436
            <xsl:with-param name="origname" select="$origname"/>
437
            <xsl:with-param name="purpose" select="$purpose"/>
438
            <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
439
            <xsl:with-param name="referrer" select="$referrer"/>
440
            <xsl:with-param name="lang" select="$lang"/>
441
            <xsl:with-param name="verbose" select="$verbose"/>
442
          </xsl:call-template>
443
        </xsl:when>
444
        <xsl:when test="$verbose = 0">
445
          <!-- silence -->
446
        </xsl:when>
447
        <xsl:otherwise>
448
          <xsl:message>
449
            <xsl:text>No template for "</xsl:text>
450
            <xsl:value-of select="$origname"/>
451
            <xsl:text>" (or any of its leaves) exists
452
in the context named "</xsl:text>
453
            <xsl:value-of select="$context"/>
454
            <xsl:text>" in the "</xsl:text>
455
            <xsl:value-of select="$lang"/>
456
            <xsl:text>" localization.</xsl:text>
457
          </xsl:message>
458
        </xsl:otherwise>
459
      </xsl:choose>
460
    </xsl:otherwise>
461
  </xsl:choose>
462
</xsl:template>
463

    
464
<!-- silently test if a gentext template exists -->
465

    
466
<xsl:template name="gentext.template.exists">
467
  <xsl:param name="context" select="'default'"/>
468
  <xsl:param name="name" select="'default'"/>
469
  <xsl:param name="origname" select="$name"/>
470
  <xsl:param name="purpose"/>
471
  <xsl:param name="xrefstyle"/>
472
  <xsl:param name="referrer"/>
473
  <xsl:param name="lang">
474
    <xsl:call-template name="l10n.language"/>
475
  </xsl:param>
476

    
477
  <xsl:variable name="template">
478
    <xsl:call-template name="gentext.template">
479
      <xsl:with-param name="context" select="$context"/>
480
      <xsl:with-param name="name" select="$name"/>
481
      <xsl:with-param name="origname" select="$origname"/>
482
      <xsl:with-param name="purpose" select="$purpose"/>
483
      <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
484
      <xsl:with-param name="referrer" select="$referrer"/>
485
      <xsl:with-param name="lang" select="$lang"/>
486
      <xsl:with-param name="verbose" select="0"/>
487
    </xsl:call-template>
488
  </xsl:variable>
489
  
490
  <xsl:choose>
491
    <xsl:when test="string-length($template) != 0">1</xsl:when>
492
    <xsl:otherwise>0</xsl:otherwise>
493
  </xsl:choose>
494
</xsl:template>
495

    
496
</xsl:stylesheet>
497

    
(39-39/78)