48
<!--@@==========================================================================
50
The language part of the top-level locale of the document
52
<xsl:param name="l10n.language">
54
<xsl:when test="contains($l10n.locale, '_')">
55
<xsl:value-of select="substring-before($l10n.locale, '_')"/>
57
<xsl:when test="contains($l10n.locale, '@')">
58
<xsl:value-of select="substring-before($l10n.locale, '@')"/>
60
<xsl:when test="contains($l10n.locale, '_')">
61
<xsl:value-of select="substring-before($l10n.locale, '@')"/>
64
<xsl:value-of select="$l10n.locale"/>
70
<!--@@==========================================================================
72
The region part of the top-level locale of the document
74
<xsl:param name="l10n.region">
75
<xsl:variable name="aft" select="substring-after($l10n.locale, '_')"/>
77
<xsl:when test="contains($aft, '@')">
78
<xsl:value-of select="substring-before($aft, '@')"/>
80
<xsl:when test="contains($aft, '.')">
81
<xsl:value-of select="substring-before($aft, '.')"/>
84
<xsl:value-of select="$aft"/>
90
<!--@@==========================================================================
92
The variant part of the top-level locale of the document
94
<xsl:param name="l10n.variant">
95
<xsl:variable name="aft" select="substring-after($l10n.locale, '@')"/>
97
<xsl:when test="contains($aft, '.')">
98
<xsl:value-of select="substring-before($aft, '.')"/>
101
<xsl:value-of select="$aft"/>
107
<!--@@==========================================================================
109
The charset part of the top-level locale of the document
111
<xsl:param name="l10n.charset">
112
<xsl:if test="contains($l10n.locale, '.')">
113
<xsl:value-of select="substring-after($l10n.locale, '.')"/>
56
<xsl:variable name="l10n.locale.list" select="str:tokenize($l10n.locale, '-_@.')"/>
118
59
<!--**==========================================================================
120
61
Looks up the translation for a string
121
$msgid: The id of the string to look up, often the string in the C locale
122
$lang: The locale to use when looking up the translated string
123
$lang_language: The language portion of the ${lang}
124
$lang_region: The region portion of ${lang}
125
$lang_variant: The variant portion of ${lang}
126
$lang_charset: The charset portion of ${lang}
127
$number: The cardinality for plural-form lookups
128
$form: The form name for plural-form lookups
62
$domain: The domain to look up the string in.
63
$msgid: The id of the string to look up, often the string in the C locale.
64
$lang: The locale to use when looking up the translated string.
65
$number: The cardinality for plural-form lookups.
66
$form: The form name for plural-form lookups.
130
68
REMARK: Lots of documentation is needed
132
70
<xsl:template name="l10n.gettext">
71
<xsl:param name="domain" select="'yelp-xsl'"/>
133
72
<xsl:param name="msgid"/>
134
<xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang |
135
ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
136
<xsl:param name="lang_language">
137
<xsl:call-template name="l10n.language">
138
<xsl:with-param name="lang" select="$lang"/>
141
<xsl:param name="lang_region">
142
<xsl:call-template name="l10n.region">
143
<xsl:with-param name="lang" select="$lang"/>
146
<xsl:param name="lang_variant">
147
<xsl:call-template name="l10n.variant">
148
<xsl:with-param name="lang" select="$lang"/>
151
<xsl:param name="lang_charset">
152
<xsl:call-template name="l10n.charset">
153
<xsl:with-param name="lang" select="$lang"/>
73
<xsl:param name="lang" select="(ancestor-or-self::*[@lang][1]/@lang |
74
ancestor-or-self::*[@xml:lang][1]/@xml:lang)
156
76
<xsl:param name="number"/>
157
77
<xsl:param name="form">
158
78
<xsl:if test="$number">
159
79
<xsl:call-template name="l10n.plural.form">
160
80
<xsl:with-param name="number" select="$number"/>
161
81
<xsl:with-param name="lang" select="$lang"/>
162
<xsl:with-param name="lang_language" select="$lang_language"/>
163
<xsl:with-param name="lang_region" select="$lang_region"/>
164
<xsl:with-param name="lang_variant" select="$lang_variant"/>
165
<xsl:with-param name="lang_charset" select="$lang_charset"/>
166
82
</xsl:call-template>
171
87
<xsl:param name="string"/>
172
88
<xsl:param name="format" select="false()"/>
174
<xsl:for-each select="$l10n">
90
<xsl:variable name="source" select="."/>
91
<xsl:variable name="normlang" select="translate($lang,
92
'_@.ABCDEFGHIJKLMNOPQRSTUVWXYZ',
93
'---abcdefghijklmnopqrstuvwxyz')"/>
94
<xsl:for-each select="document(concat('domains/', $domain, '.xml'))">
95
<xsl:variable name="msg" select="key('msg', concat($msgid, '__LC__', $normlang))"/>
176
<!-- fe_fi@fo.fum -->
177
<xsl:when test="($lang_region and $lang_variant and $lang_charset) and
178
key('msg', concat($msgid, '__LC__',
179
$lang_language, '_', $lang_region,
181
'.', $lang_charset))">
182
<xsl:call-template name="l10n.gettext.msg">
185
select="key('msg', concat($msgid, '__LC__',
186
$lang_language, '_', $lang_region,
188
'.', $lang_charset))"/>
189
<xsl:with-param name="form" select="$form"/>
190
<xsl:with-param name="node" select="$node"/>
191
<xsl:with-param name="role" select="$role"/>
192
<xsl:with-param name="string" select="$string"/>
193
<xsl:with-param name="format" select="$format"/>
197
<xsl:when test="($lang_region and $lang_variant) and
198
key('msg', concat($msgid, '__LC__',
199
$lang_language, '_', $lang_region,
200
'@', $lang_variant))">
201
<xsl:call-template name="l10n.gettext.msg">
204
select="key('msg', concat($msgid, '__LC__',
205
$lang_language, '_', $lang_region,
206
'@', $lang_variant))"/>
207
<xsl:with-param name="form" select="$form"/>
208
<xsl:with-param name="node" select="$node"/>
209
<xsl:with-param name="role" select="$role"/>
210
<xsl:with-param name="string" select="$string"/>
211
<xsl:with-param name="format" select="$format"/>
215
<xsl:when test="($lang_variant and $lang_charset) and
216
key('msg', concat($msgid, '__LC__',
217
$lang_language, '@', $lang_variant,
218
'.', $lang_charset))">
219
<xsl:call-template name="l10n.gettext.msg">
222
select="key('msg', concat($msgid, '__LC__',
223
$lang_language, '@', $lang_variant,
224
'.', $lang_charset))"/>
225
<xsl:with-param name="form" select="$form"/>
226
<xsl:with-param name="node" select="$node"/>
227
<xsl:with-param name="role" select="$role"/>
228
<xsl:with-param name="string" select="$string"/>
229
<xsl:with-param name="format" select="$format"/>
233
<xsl:when test="($lang_variant) and
234
key('msg', concat($msgid, '__LC__',
235
$lang_language, '@', $lang_variant))">
236
<xsl:call-template name="l10n.gettext.msg">
239
select="key('msg', concat($msgid, '__LC__',
240
$lang_language, '@', $lang_variant))"/>
241
<xsl:with-param name="form" select="$form"/>
242
<xsl:with-param name="node" select="$node"/>
243
<xsl:with-param name="role" select="$role"/>
244
<xsl:with-param name="string" select="$string"/>
245
<xsl:with-param name="format" select="$format"/>
249
<xsl:when test="($lang_region and $lang_charset) and
250
key('msg', concat($msgid, '__LC__',
251
$lang_language, '_', $lang_region,
252
'.', $lang_charset))">
253
<xsl:call-template name="l10n.gettext.msg">
256
select="key('msg', concat($msgid, '__LC__',
257
$lang_language, '_', $lang_region,
258
'.', $lang_charset))"/>
259
<xsl:with-param name="form" select="$form"/>
260
<xsl:with-param name="node" select="$node"/>
261
<xsl:with-param name="role" select="$role"/>
262
<xsl:with-param name="string" select="$string"/>
263
<xsl:with-param name="format" select="$format"/>
267
<xsl:when test="($lang_region) and
268
key('msg', concat($msgid, '__LC__',
269
$lang_language, '_', $lang_region))">
270
<xsl:call-template name="l10n.gettext.msg">
273
select="key('msg', concat($msgid, '__LC__',
274
$lang_language, '_', $lang_region))"/>
275
<xsl:with-param name="form" select="$form"/>
276
<xsl:with-param name="node" select="$node"/>
277
<xsl:with-param name="role" select="$role"/>
278
<xsl:with-param name="string" select="$string"/>
279
<xsl:with-param name="format" select="$format"/>
283
<xsl:when test="($lang_charset) and
284
key('msg', concat($msgid, '__LC__',
285
$lang_language, '.', $lang_charset))">
286
<xsl:call-template name="l10n.gettext.msg">
289
select="key('msg', concat($msgid, '__LC__',
290
$lang_language, '.', $lang_charset))"/>
291
<xsl:with-param name="form" select="$form"/>
292
<xsl:with-param name="node" select="$node"/>
293
<xsl:with-param name="role" select="$role"/>
294
<xsl:with-param name="string" select="$string"/>
295
<xsl:with-param name="format" select="$format"/>
299
<xsl:when test="key('msg', concat($msgid, '__LC__', $lang_language))">
300
<xsl:call-template name="l10n.gettext.msg">
303
select="key('msg', concat($msgid, '__LC__', $lang_language))"/>
304
<xsl:with-param name="form" select="$form"/>
305
<xsl:with-param name="node" select="$node"/>
306
<xsl:with-param name="role" select="$role"/>
307
<xsl:with-param name="string" select="$string"/>
308
<xsl:with-param name="format" select="$format"/>
312
<xsl:when test="key('msg', concat($msgid, '__LC__C'))">
313
<xsl:call-template name="l10n.gettext.msg">
315
name="msg" select="key('msg', concat($msgid, '__LC__C'))"/>
316
<xsl:with-param name="form" select="$form"/>
317
<xsl:with-param name="node" select="$node"/>
318
<xsl:with-param name="role" select="$role"/>
319
<xsl:with-param name="string" select="$string"/>
320
<xsl:with-param name="format" select="$format"/>
324
<xsl:when test="key('msg', concat($msgid, '__LC__'))">
325
<xsl:call-template name="l10n.gettext.msg">
327
name="msg" select="key('msg', concat($msgid, '__LC__'))"/>
328
<xsl:with-param name="form" select="$form"/>
329
<xsl:with-param name="node" select="$node"/>
330
<xsl:with-param name="role" select="$role"/>
331
<xsl:with-param name="string" select="$string"/>
332
<xsl:with-param name="format" select="$format"/>
97
<xsl:when test="$msg">
98
<xsl:for-each select="$source">
99
<xsl:call-template name="l10n.gettext.msg">
100
<xsl:with-param name="msg" select="$msg"/>
101
<xsl:with-param name="form" select="$form"/>
102
<xsl:with-param name="node" select="$node"/>
103
<xsl:with-param name="role" select="$role"/>
104
<xsl:with-param name="string" select="$string"/>
105
<xsl:with-param name="format" select="$format"/>
109
<xsl:when test="contains($normlang, '-')">
110
<xsl:variable name="newlang">
111
<xsl:for-each select="str:split($normlang, '-')[position() != last()]">
112
<xsl:if test="position() != 1">
113
<xsl:text>-</xsl:text>
115
<xsl:value-of select="."/>
118
<xsl:for-each select="$source">
119
<xsl:call-template name="l10n.gettext">
120
<xsl:with-param name="domain" select="$domain"/>
121
<xsl:with-param name="msgid" select="$msgid"/>
122
<xsl:with-param name="lang" select="$newlang"/>
123
<xsl:with-param name="number" select="$number"/>
124
<xsl:with-param name="form" select="$form"/>
125
<xsl:with-param name="role" select="$role"/>
126
<xsl:with-param name="string" select="$string"/>
127
<xsl:with-param name="format" select="$format"/>
131
<xsl:when test="$normlang = 'c'">
132
<xsl:value-of select="$msgid"/>
337
<xsl:text>No translation available for string '</xsl:text>
338
<xsl:value-of select="$msgid"/>
339
<xsl:text>'.</xsl:text>
341
<xsl:value-of select="$msgid"/>
135
<xsl:for-each select="$source">
136
<xsl:call-template name="l10n.gettext">
137
<xsl:with-param name="domain" select="$domain"/>
138
<xsl:with-param name="msgid" select="$msgid"/>
139
<xsl:with-param name="lang" select="'C'"/>
140
<xsl:with-param name="number" select="$number"/>
141
<xsl:with-param name="form" select="$form"/>
142
<xsl:with-param name="role" select="$role"/>
143
<xsl:with-param name="string" select="$string"/>
144
<xsl:with-param name="format" select="$format"/>
881
<!--**==========================================================================
883
Extracts the langauge portion of a locale
884
$lang: The locale to extract the language from
886
REMARK: Lots of documentation is needed
888
<xsl:template name="l10n.language">
889
<xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang |
890
ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
892
<xsl:when test="$lang = $l10n.locale">
893
<xsl:value-of select="$l10n.language"/>
895
<xsl:when test="contains($lang, '_')">
896
<xsl:value-of select="substring-before($lang, '_')"/>
898
<xsl:when test="contains($lang, '@')">
899
<xsl:value-of select="substring-before($lang, '@')"/>
901
<xsl:when test="contains($lang, '_')">
902
<xsl:value-of select="substring-before($lang, '@')"/>
905
<xsl:value-of select="$lang"/>
911
<!--**==========================================================================
913
Extracts the region portion of a locale
914
$lang: The locale to extract the region from
916
REMARK: Lots of documentation is needed
918
<xsl:template name="l10n.region">
919
<xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang |
920
ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
922
<xsl:when test="$lang = $l10n.locale">
923
<xsl:value-of select="$l10n.region"/>
925
<xsl:when test="contains($lang, '_')">
926
<xsl:variable name="aft" select="substring-after($lang, '_')"/>
928
<xsl:when test="contains($aft, '@')">
929
<xsl:value-of select="substring-before($aft, '@')"/>
931
<xsl:when test="contains($aft, '.')">
932
<xsl:value-of select="substring-before($aft, '.')"/>
935
<xsl:value-of select="$aft"/>
943
<!--**==========================================================================
945
Extracts the variant portion of a locale
946
$lang: The locale to extract the variant from
948
REMARK: Lots of documentation is needed
950
<xsl:template name="l10n.variant">
951
<xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang |
952
ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
954
<xsl:when test="$lang = $l10n.locale">
955
<xsl:value-of select="$l10n.variant"/>
957
<xsl:when test="contains($lang, '@')">
958
<xsl:variable name="aft" select="substring-after($lang, '@')"/>
960
<xsl:when test="contains($aft, '.')">
961
<xsl:value-of select="substring-before($aft, '.')"/>
964
<xsl:value-of select="$aft"/>
972
<!--**==========================================================================
974
Extracts the charset portion of a locale
975
$lang: The locale to extract the charset from
977
REMARK: Lots of documentation is needed
979
<xsl:template name="l10n.charset">
980
<xsl:param name="lang" select="ancestor-or-self::*[@lang][1]/@lang |
981
ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
983
<xsl:when test="$lang = $l10n.locale">
984
<xsl:value-of select="$l10n.charset"/>
986
<xsl:when test="contains($lang, '.')">
987
<xsl:value-of select="substring-after($lang, '.')"/>
993
638
<!--%%==========================================================================