jsdialog: use single constructor for builder
[LibreOffice.git] / officecfg / util / alllang.xsl
blobb9b2d19835519735e784f49399a0b094aae8d256
1 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2 <!--
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 -->
20 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
21 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22 xmlns:xs="http://www.w3.org/2001/XMLSchema"
23 xmlns:oor="http://openoffice.org/2001/registry"
24 xmlns:install="http://openoffice.org/2004/installation"
25 exclude-result-prefixes="install">
27 <!-- Get the correct format -->
28 <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
30 <!--************************** PARAMETER ******************************** -->
31 <xsl:param name="locale"/>
32 <xsl:param name="module"/>
33 <xsl:param name="xcs"/>
34 <xsl:param name="schemaRoot">.</xsl:param>
35 <xsl:param name="fallback-locale">en-US</xsl:param>
37 <xsl:param name="LIBO_SHARE_FOLDER"/>
38 <xsl:param name="LIBO_SHARE_HELP_FOLDER"/>
40 <xsl:variable name="schemaRootURL">
41 <xsl:value-of select="$schemaRoot"/>
42 </xsl:variable>
43 <xsl:variable name="schemaURL">
44 <xsl:value-of select="$xcs"/>
45 </xsl:variable>
47 <!--************************** TEMPLATES ******************************** -->
48 <!-- ensure that at least root is available -->
49 <xsl:template match="/oor:component-data">
50 <xsl:copy>
51 <xsl:choose>
52 <xsl:when test="string-length($locale)">
53 <xsl:apply-templates select = "@*" mode="locale"/>
54 <xsl:apply-templates select = "node|prop" mode="locale"/>
55 </xsl:when>
56 <xsl:otherwise>
57 <xsl:apply-templates select = "@*"/>
58 <xsl:for-each select="node|prop">
59 <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/>
60 <xsl:apply-templates select=".">
61 <xsl:with-param name="component-schema" select="$component-schema"/>
62 <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/>
63 <xsl:with-param name="find-module" select="$module"/>
64 </xsl:apply-templates>
65 </xsl:for-each>
66 </xsl:otherwise>
67 </xsl:choose>
68 </xsl:copy>
69 </xsl:template>
71 <!-- locale dependent data -->
72 <xsl:template match="node|prop" mode = "locale">
73 <xsl:choose>
74 <xsl:when test="$locale=$fallback-locale">
75 <xsl:if test="descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]">
76 <xsl:copy>
77 <xsl:apply-templates select = "@*" mode="locale"/>
78 <xsl:apply-templates select = "node|prop|value" mode = "locale"/>
79 </xsl:copy>
80 </xsl:if>
81 </xsl:when>
82 <xsl:otherwise>
83 <xsl:if test="descendant::value[@xml:lang = $locale]">
84 <xsl:copy>
85 <xsl:apply-templates select = "@*" mode="locale"/>
86 <xsl:apply-templates select = "node|prop|value" mode = "locale"/>
87 </xsl:copy>
88 </xsl:if>
89 </xsl:otherwise>
90 </xsl:choose>
91 </xsl:template>
93 <xsl:template match="value" mode="locale">
94 <xsl:if test="@xml:lang=$locale and not(@install:module)">
95 <xsl:copy>
96 <xsl:apply-templates select = "@*" mode="locale"/>
97 <xsl:apply-templates select="node()"/>
98 </xsl:copy>
99 </xsl:if>
100 </xsl:template>
102 <xsl:template match = "@*" mode="locale">
103 <xsl:copy/>
104 </xsl:template>
106 <!-- suppress all merge instructions -->
107 <xsl:template match = "@oor:op" mode="locale"/>
109 <!-- suppress all module markers -->
110 <xsl:template match = "@install:module" mode="locale"/>
112 <!-- locale independent data -->
114 <!-- handle template references -->
115 <xsl:template name="copy-resolve-template">
116 <xsl:param name = "node-type"/>
117 <xsl:param name = "schema-type"/>
118 <xsl:param name = "component-schema"/>
120 <xsl:choose>
121 <xsl:when test="$schema-type='node-ref'">
122 <xsl:apply-templates select=".">
123 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
124 <xsl:with-param name="component-schema" select="$component-schema"/>
125 </xsl:apply-templates>
126 </xsl:when>
127 <xsl:when test="$schema-type='set'">
128 <xsl:copy>
129 <xsl:apply-templates select = "@*" />
130 <xsl:for-each select="node|prop">
131 <xsl:apply-templates select=".">
132 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
133 <xsl:with-param name="component-schema" select="$component-schema"/>
134 </xsl:apply-templates>
135 </xsl:for-each>
136 </xsl:copy>
137 </xsl:when>
138 <xsl:otherwise>
139 <xsl:message terminate="yes">ERROR: The schema element for a <xsl:value-of select="$schema-type"/>
140 should not have a node-type.
141 </xsl:message>
142 </xsl:otherwise>
143 </xsl:choose>
144 </xsl:template>
146 <xsl:template name="copy-node">
147 <xsl:param name = "context"/>
148 <xsl:param name = "component-schema"/>
150 <xsl:choose>
151 <!-- look for matching templates in other components -->
152 <xsl:when test="$context/@oor:node-type and $context/@oor:component">
153 <xsl:variable name="fileURL">
154 <xsl:call-template name="composeFileURL">
155 <xsl:with-param name="component-schema" select="$component-schema"/>
156 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
157 </xsl:call-template>
158 </xsl:variable>
159 <xsl:call-template name="copy-resolve-template">
160 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
161 <xsl:with-param name="schema-type" select="local-name($context)"/>
162 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
163 </xsl:call-template>
164 </xsl:when>
165 <!-- look for matching templates within the same component -->
166 <xsl:when test="$context/@oor:node-type">
167 <xsl:call-template name="copy-resolve-template">
168 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
169 <xsl:with-param name="schema-type" select="local-name($context)"/>
170 <xsl:with-param name="component-schema" select="$component-schema"/>
171 </xsl:call-template>
172 </xsl:when>
173 <xsl:otherwise>
174 <xsl:copy>
175 <xsl:apply-templates select = "@*" />
176 <xsl:for-each select="node|prop">
177 <xsl:apply-templates select=".">
178 <xsl:with-param name="component-schema" select="$component-schema"/>
179 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
180 </xsl:apply-templates>
181 </xsl:for-each>
182 </xsl:copy>
183 </xsl:otherwise>
184 </xsl:choose>
185 </xsl:template>
187 <xsl:template match="node">
188 <xsl:param name = "context"/>
189 <xsl:param name = "component-schema"/>
191 <xsl:variable name="applicable-values" select="descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/>
192 <xsl:variable name="substantive-nodes" select="descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/>
194 <xsl:choose>
195 <!-- go ahead, if we are in the active module -->
196 <xsl:when test="ancestor-or-self::*/@install:module=$module">
197 <xsl:if test="$applicable-values | $substantive-nodes">
198 <xsl:call-template name="copy-node">
199 <xsl:with-param name="component-schema" select="$component-schema"/>
200 <xsl:with-param name="context" select="$context"/>
201 </xsl:call-template>
202 </xsl:if>
203 </xsl:when>
204 <!-- strip data from wrong module -->
205 <xsl:when test="ancestor-or-self::*/@install:module"/>
206 <!-- looking for module -->
207 <xsl:when test="$module">
208 <xsl:if test="($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module">
209 <xsl:call-template name="copy-node">
210 <xsl:with-param name="component-schema" select="$component-schema"/>
211 <xsl:with-param name="context" select="$context"/>
212 </xsl:call-template>
213 </xsl:if>
214 </xsl:when>
215 <!-- copying non-module data -->
216 <xsl:otherwise>
217 <xsl:if test="($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]">
218 <xsl:call-template name="copy-node">
219 <xsl:with-param name="component-schema" select="$component-schema"/>
220 <xsl:with-param name="context" select="$context"/>
221 </xsl:call-template>
222 </xsl:if>
223 </xsl:otherwise>
224 </xsl:choose>
225 </xsl:template>
227 <xsl:template match="prop">
228 <xsl:param name = "context"/>
229 <xsl:choose>
230 <xsl:when test="$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/>
231 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
232 <xsl:when test="not ($context) or @oor:finalized='true' or @oor:op!='modify'">
233 <xsl:copy>
234 <xsl:apply-templates select = "@*"/>
235 <xsl:apply-templates select = "value"/>
236 </xsl:copy>
237 </xsl:when>
238 <xsl:when test="value[not (@xml:lang) or @install:module]">
239 <xsl:if test="value[not(@install:module) or @install:module=$module]">
240 <!-- copy locale independent values only, if the values differ -->
241 <xsl:variable name="isRedundant">
242 <xsl:call-template name="isRedundant">
243 <xsl:with-param name="schemaval" select="$context/value"/>
244 <xsl:with-param name="dataval" select="value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/>
245 </xsl:call-template>
246 </xsl:variable>
247 <xsl:if test="$isRedundant ='false'">
248 <xsl:copy>
249 <xsl:apply-templates select = "@*"/>
250 <xsl:apply-templates select = "value"/>
251 </xsl:copy>
252 </xsl:if>
253 </xsl:if>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:copy>
257 <xsl:apply-templates select = "@*"/>
258 <xsl:apply-templates select = "value" mode="fallback-locale"/>
259 </xsl:copy>
260 </xsl:otherwise>
261 </xsl:choose>
262 </xsl:template>
264 <xsl:template match="value">
265 <xsl:choose>
266 <xsl:when test="@xml:lang and not(@install:module)"/>
267 <xsl:when test="$module and not(ancestor-or-self::*/@install:module=$module)"/>
268 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
269 <xsl:otherwise>
270 <xsl:copy>
271 <xsl:apply-templates select = "@*|node()"/>
272 </xsl:copy>
273 </xsl:otherwise>
274 </xsl:choose>
275 </xsl:template>
277 <xsl:template match="value" mode="fallback-locale">
278 <xsl:if test="@xml:lang=$fallback-locale and not(@install:module)">
279 <xsl:copy>
280 <xsl:apply-templates select = "@*|node()"/>
281 </xsl:copy>
282 </xsl:if>
283 </xsl:template>
285 <xsl:template match ="it|unicode">
286 <xsl:copy>
287 <xsl:apply-templates select = "@*|node()"/>
288 </xsl:copy>
289 </xsl:template>
291 <xsl:template match = "@*">
292 <xsl:copy/>
293 </xsl:template>
295 <!-- suppress all merge instructions, that are out-of-module -->
296 <xsl:template match = "@oor:op">
297 <xsl:if test="not($module) or ancestor::*/@install:module">
298 <xsl:copy/>
299 </xsl:if>
300 </xsl:template>
302 <!-- suppress all module markers -->
303 <xsl:template match = "@install:module"/>
305 <!-- compares two values -->
306 <xsl:template name="isRedundant">
307 <xsl:param name = "schemaval"/>
308 <xsl:param name = "dataval"/>
309 <xsl:choose>
310 <xsl:when test="not ($dataval)">
311 <xsl:value-of select="true()"/>
312 </xsl:when>
313 <xsl:when test="$dataval/@oor:external">
314 <xsl:value-of select="false()"/>
315 </xsl:when>
316 <xsl:when test="not ($schemaval)">
317 <xsl:choose>
318 <xsl:when test="$dataval/@xsi:nil='true'">
319 <xsl:value-of select="true()"/>
320 </xsl:when>
321 <xsl:otherwise>
322 <xsl:value-of select="false()"/>
323 </xsl:otherwise>
324 </xsl:choose>
325 </xsl:when>
326 <xsl:when test="$schemaval != $dataval">
327 <xsl:value-of select="false()"/>
328 </xsl:when>
329 <xsl:otherwise>
330 <xsl:value-of select="true()"/>
331 </xsl:otherwise>
332 </xsl:choose>
333 </xsl:template>
335 <xsl:template name="composeFileURL">
336 <xsl:param name="componentName"/>
337 <xsl:variable name="fileURL">
338 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
339 </xsl:variable>
340 <xsl:value-of select="$fileURL"/>
341 </xsl:template>
343 <xsl:template match="@oor:name">
344 <xsl:attribute name="oor:name">
345 <xsl:call-template name="replacetwo">
346 <xsl:with-param name="input" select="current()"/>
347 <xsl:with-param name="pattern1" select="'@LIBO_SHARE_FOLDER@'"/>
348 <xsl:with-param name="replace1" select="$LIBO_SHARE_FOLDER"/>
349 <xsl:with-param name="pattern2" select="'@LIBO_SHARE_HELP_FOLDER@'"/>
350 <xsl:with-param name="replace2" select="$LIBO_SHARE_HELP_FOLDER"/>
351 </xsl:call-template>
352 </xsl:attribute>
353 </xsl:template>
355 <xsl:template match="text()">
356 <xsl:call-template name="replacetwo">
357 <xsl:with-param name="input" select="current()"/>
358 <xsl:with-param name="pattern1" select="'@LIBO_SHARE_FOLDER@'"/>
359 <xsl:with-param name="replace1" select="$LIBO_SHARE_FOLDER"/>
360 <xsl:with-param name="pattern2" select="'@LIBO_SHARE_HELP_FOLDER@'"/>
361 <xsl:with-param name="replace2" select="$LIBO_SHARE_HELP_FOLDER"/>
362 </xsl:call-template>
363 </xsl:template>
365 <xsl:template name="replace">
366 <xsl:param name="input"/>
367 <xsl:param name="pattern"/>
368 <xsl:param name="replace"/>
369 <xsl:choose>
370 <xsl:when test="contains($input, $pattern)">
371 <xsl:value-of select="substring-before($input, $pattern)"/>
372 <xsl:value-of select="$replace"/>
373 <xsl:call-template name="replace">
374 <xsl:with-param
375 name="input" select="substring-after($input, $pattern)"/>
376 <xsl:with-param name="pattern" select="$pattern"/>
377 <xsl:with-param name="replace" select="$replace"/>
378 </xsl:call-template>
379 </xsl:when>
380 <xsl:otherwise>
381 <xsl:value-of select="$input"/>
382 </xsl:otherwise>
383 </xsl:choose>
384 </xsl:template>
386 <xsl:template name="replacetwo">
387 <xsl:param name="input"/>
388 <xsl:param name="pattern1"/>
389 <xsl:param name="replace1"/>
390 <xsl:param name="pattern2"/>
391 <xsl:param name="replace2"/>
392 <xsl:choose>
393 <xsl:when test="contains($input, $pattern1)">
394 <xsl:call-template name="replace">
395 <xsl:with-param
396 name="input" select="substring-before($input, $pattern1)"/>
397 <xsl:with-param name="pattern" select="$pattern2"/>
398 <xsl:with-param name="replace" select="$replace2"/>
399 </xsl:call-template>
400 <xsl:value-of select="$replace1"/>
401 <xsl:call-template name="replacetwo">
402 <xsl:with-param
403 name="input" select="substring-after($input, $pattern1)"/>
404 <xsl:with-param name="pattern1" select="$pattern1"/>
405 <xsl:with-param name="replace1" select="$replace1"/>
406 <xsl:with-param name="pattern2" select="$pattern2"/>
407 <xsl:with-param name="replace2" select="$replace2"/>
408 </xsl:call-template>
409 </xsl:when>
410 <xsl:otherwise>
411 <xsl:call-template name="replace">
412 <xsl:with-param
413 name="input" select="$input"/>
414 <xsl:with-param name="pattern" select="$pattern2"/>
415 <xsl:with-param name="replace" select="$replace2"/>
416 </xsl:call-template>
417 </xsl:otherwise>
418 </xsl:choose>
419 </xsl:template>
421 </xsl:transform>