update credits
[LibreOffice.git] / officecfg / util / alllang.xsl
blob252a0beefe66fa06852613f6cf933754cd928562
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:variable name="schemaRootURL">
38 <xsl:value-of select="$schemaRoot"/>
39 </xsl:variable>
40 <xsl:variable name="schemaURL">
41 <xsl:value-of select="$xcs"/>
42 </xsl:variable>
44 <!--************************** TEMPLATES ******************************** -->
45 <!-- ensure that at least root is available -->
46 <xsl:template match="/oor:component-data">
47 <xsl:copy>
48 <xsl:choose>
49 <xsl:when test="string-length($locale)">
50 <xsl:apply-templates select = "@*" mode="locale"/>
51 <xsl:apply-templates select = "node|prop" mode="locale"/>
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:apply-templates select = "@*"/>
55 <xsl:for-each select="node|prop">
56 <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/>
57 <xsl:apply-templates select=".">
58 <xsl:with-param name="component-schema" select="$component-schema"/>
59 <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/>
60 <xsl:with-param name="find-module" select="$module"/>
61 </xsl:apply-templates>
62 </xsl:for-each>
63 </xsl:otherwise>
64 </xsl:choose>
65 </xsl:copy>
66 </xsl:template>
68 <!-- locale dependent data -->
69 <xsl:template match="node|prop" mode = "locale">
70 <xsl:choose>
71 <xsl:when test="$locale=$fallback-locale">
72 <xsl:if test="descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]">
73 <xsl:copy>
74 <xsl:apply-templates select = "@*" mode="locale"/>
75 <xsl:apply-templates select = "node|prop|value" mode = "locale"/>
76 </xsl:copy>
77 </xsl:if>
78 </xsl:when>
79 <xsl:otherwise>
80 <xsl:if test="descendant::value[@xml:lang = $locale]">
81 <xsl:copy>
82 <xsl:apply-templates select = "@*" mode="locale"/>
83 <xsl:apply-templates select = "node|prop|value" mode = "locale"/>
84 </xsl:copy>
85 </xsl:if>
86 </xsl:otherwise>
87 </xsl:choose>
88 </xsl:template>
90 <xsl:template match="value" mode="locale">
91 <xsl:if test="@xml:lang=$locale and not(@install:module)">
92 <xsl:copy>
93 <xsl:apply-templates select = "@*" mode="locale"/>
94 <xsl:copy-of select="node()"/>
95 </xsl:copy>
96 </xsl:if>
97 </xsl:template>
99 <xsl:template match = "@*" mode="locale">
100 <xsl:copy/>
101 </xsl:template>
103 <!-- suppress all merge instructions -->
104 <xsl:template match = "@oor:op" mode="locale"/>
106 <!-- suppress all module markers -->
107 <xsl:template match = "@install:module" mode="locale"/>
109 <!-- locale independent data -->
111 <!-- handle template references -->
112 <xsl:template name="copy-resolve-template">
113 <xsl:param name = "node-type"/>
114 <xsl:param name = "schema-type"/>
115 <xsl:param name = "component-schema"/>
117 <xsl:choose>
118 <xsl:when test="$schema-type='node-ref'">
119 <xsl:apply-templates select=".">
120 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
121 <xsl:with-param name="component-schema" select="$component-schema"/>
122 </xsl:apply-templates>
123 </xsl:when>
124 <xsl:when test="$schema-type='set'">
125 <xsl:copy>
126 <xsl:apply-templates select = "@*" />
127 <xsl:for-each select="node|prop">
128 <xsl:apply-templates select=".">
129 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
130 <xsl:with-param name="component-schema" select="$component-schema"/>
131 </xsl:apply-templates>
132 </xsl:for-each>
133 </xsl:copy>
134 </xsl:when>
135 <xsl:otherwise>
136 <xsl:message terminate="yes">ERROR: The schema element for a <xsl:value-of select="$schema-type"/>
137 should not have a node-type.
138 </xsl:message>
139 </xsl:otherwise>
140 </xsl:choose>
141 </xsl:template>
143 <xsl:template name="copy-node">
144 <xsl:param name = "context"/>
145 <xsl:param name = "component-schema"/>
147 <xsl:choose>
148 <!-- look for matching templates in other components -->
149 <xsl:when test="$context/@oor:node-type and $context/@oor:component">
150 <xsl:variable name="fileURL">
151 <xsl:call-template name="composeFileURL">
152 <xsl:with-param name="component-schema" select="$component-schema"/>
153 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
154 </xsl:call-template>
155 </xsl:variable>
156 <xsl:call-template name="copy-resolve-template">
157 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
158 <xsl:with-param name="schema-type" select="local-name($context)"/>
159 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
160 </xsl:call-template>
161 </xsl:when>
162 <!-- look for matching templates within the same component -->
163 <xsl:when test="$context/@oor:node-type">
164 <xsl:call-template name="copy-resolve-template">
165 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
166 <xsl:with-param name="schema-type" select="local-name($context)"/>
167 <xsl:with-param name="component-schema" select="$component-schema"/>
168 </xsl:call-template>
169 </xsl:when>
170 <xsl:otherwise>
171 <xsl:copy>
172 <xsl:apply-templates select = "@*" />
173 <xsl:for-each select="node|prop">
174 <xsl:apply-templates select=".">
175 <xsl:with-param name="component-schema" select="$component-schema"/>
176 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
177 </xsl:apply-templates>
178 </xsl:for-each>
179 </xsl:copy>
180 </xsl:otherwise>
181 </xsl:choose>
182 </xsl:template>
184 <xsl:template match="node">
185 <xsl:param name = "context"/>
186 <xsl:param name = "component-schema"/>
188 <xsl:variable name="applicable-values" select="descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/>
189 <xsl:variable name="substantive-nodes" select="descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/>
191 <xsl:choose>
192 <!-- go ahead, if we are in the active module -->
193 <xsl:when test="ancestor-or-self::*/@install:module=$module">
194 <xsl:if test="$applicable-values | $substantive-nodes">
195 <xsl:call-template name="copy-node">
196 <xsl:with-param name="component-schema" select="$component-schema"/>
197 <xsl:with-param name="context" select="$context"/>
198 </xsl:call-template>
199 </xsl:if>
200 </xsl:when>
201 <!-- strip data from wrong module -->
202 <xsl:when test="ancestor-or-self::*/@install:module"/>
203 <!-- looking for module -->
204 <xsl:when test="$module">
205 <xsl:if test="($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module">
206 <xsl:call-template name="copy-node">
207 <xsl:with-param name="component-schema" select="$component-schema"/>
208 <xsl:with-param name="context" select="$context"/>
209 </xsl:call-template>
210 </xsl:if>
211 </xsl:when>
212 <!-- copying non-module data -->
213 <xsl:otherwise>
214 <xsl:if test="($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]">
215 <xsl:call-template name="copy-node">
216 <xsl:with-param name="component-schema" select="$component-schema"/>
217 <xsl:with-param name="context" select="$context"/>
218 </xsl:call-template>
219 </xsl:if>
220 </xsl:otherwise>
221 </xsl:choose>
222 </xsl:template>
224 <xsl:template match="prop">
225 <xsl:param name = "context"/>
226 <xsl:choose>
227 <xsl:when test="$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/>
228 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
229 <xsl:when test="not ($context) or @oor:finalized='true' or @oor:op!='modify'">
230 <xsl:copy>
231 <xsl:apply-templates select = "@*"/>
232 <xsl:apply-templates select = "value"/>
233 </xsl:copy>
234 </xsl:when>
235 <xsl:when test="value[not (@xml:lang) or @install:module]">
236 <xsl:if test="value[not(@install:module) or @install:module=$module]">
237 <!-- copy locale independent values only, if the values differ -->
238 <xsl:variable name="isRedundant">
239 <xsl:call-template name="isRedundant">
240 <xsl:with-param name="schemaval" select="$context/value"/>
241 <xsl:with-param name="dataval" select="value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/>
242 </xsl:call-template>
243 </xsl:variable>
244 <xsl:if test="$isRedundant ='false'">
245 <xsl:copy>
246 <xsl:apply-templates select = "@*"/>
247 <xsl:apply-templates select = "value"/>
248 </xsl:copy>
249 </xsl:if>
250 </xsl:if>
251 </xsl:when>
252 <xsl:otherwise>
253 <xsl:copy>
254 <xsl:apply-templates select = "@*"/>
255 <xsl:apply-templates select = "value" mode="fallback-locale"/>
256 </xsl:copy>
257 </xsl:otherwise>
258 </xsl:choose>
259 </xsl:template>
261 <xsl:template match="value">
262 <xsl:choose>
263 <xsl:when test="@xml:lang and not(@install:module)"/>
264 <xsl:when test="$module and not(ancestor-or-self::*/@install:module=$module)"/>
265 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
266 <xsl:otherwise>
267 <xsl:copy>
268 <xsl:apply-templates select = "@*"/>
269 <xsl:copy-of select="node()"/>
270 </xsl:copy>
271 </xsl:otherwise>
272 </xsl:choose>
273 </xsl:template>
275 <xsl:template match="value" mode="fallback-locale">
276 <xsl:if test="@xml:lang=$fallback-locale and not(@install:module)">
277 <xsl:copy>
278 <xsl:apply-templates select = "@*"/>
279 <xsl:copy-of select="node()"/>
280 </xsl:copy>
281 </xsl:if>
282 </xsl:template>
284 <xsl:template match = "@*">
285 <xsl:copy/>
286 </xsl:template>
288 <!-- suppress all merge instructions, that are out-of-module -->
289 <xsl:template match = "@oor:op">
290 <xsl:if test="not($module) or ancestor::*/@install:module">
291 <xsl:copy/>
292 </xsl:if>
293 </xsl:template>
295 <!-- suppress all module markers -->
296 <xsl:template match = "@install:module"/>
298 <!-- compares two values -->
299 <xsl:template name="isRedundant">
300 <xsl:param name = "schemaval"/>
301 <xsl:param name = "dataval"/>
302 <xsl:choose>
303 <xsl:when test="not ($dataval)">
304 <xsl:value-of select="true()"/>
305 </xsl:when>
306 <xsl:when test="$dataval/@oor:external">
307 <xsl:value-of select="false()"/>
308 </xsl:when>
309 <xsl:when test="not ($schemaval)">
310 <xsl:choose>
311 <xsl:when test="$dataval/@xsi:nil='true'">
312 <xsl:value-of select="true()"/>
313 </xsl:when>
314 <xsl:otherwise>
315 <xsl:value-of select="false()"/>
316 </xsl:otherwise>
317 </xsl:choose>
318 </xsl:when>
319 <xsl:when test="$schemaval != $dataval">
320 <xsl:value-of select="false()"/>
321 </xsl:when>
322 <xsl:otherwise>
323 <xsl:value-of select="true()"/>
324 </xsl:otherwise>
325 </xsl:choose>
326 </xsl:template>
328 <xsl:template name="composeFileURL">
329 <xsl:param name="componentName"/>
330 <xsl:variable name="fileURL">
331 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
332 </xsl:variable>
333 <xsl:value-of select="$fileURL"/>
334 </xsl:template>
336 </xsl:transform>