lang-lab.mkiv /size: 13 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=lang-lab,
3
%D version=1997.08.27,
4
%D title=\CONTEXT\ Language Macros,
5
%D subtitle=Labels,
6
%D author=Hans Hagen / Tobias Burnus,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\writestatus
{
loading
}{
ConTeXt
Language
Macros
/
Labels
}
15 16
\registerctxluafile
{
lang
-
lab
}{}
17
\registerctxluafile
{
lang
-
txt
}{}
18 19
\unprotect
20 21
%D Left-overs:
22 23
\ifdefined
\sixperemspace
\else
24
\def
\sixperemspace
{
\normalUchar
"
2
0
0
6
}
25
\fi
26 27
%D In this module we deal with language dependant labels and prefixes, like in {\em
28
%D Figure~12} and {\em Chapter 1}. In this file we set the default values. Users can
29
%D easily overrule these.
30
%D
31
%D This module is dedicated to the grandfather of Tobias Burnus, who's extensive
32
%D languages oriented library helped us a lot in finding the right translations. All
33
%D those labels are collected in files that reflect their common ancestor.
34
%D
35
%D Not all languages can be satisfied with the labeling mechanism as provided here.
36
%D Chinese for instance put a label in front as well as after a part number. This is
37
%D why the current implementation of labels supports two labels too.
38 39
%D \macros
40
%D {setupheadtext, setuplabeltext}
41
%D
42
%D First we present some macros that deal with what we will call head and label
43
%D texts. Such texts are defines by:
44
%D
45
%D \showsetup{setupheadtext}
46
%D \showsetup{setuplabeltext}
47
%D
48
%D A regular \CONTEXT\ stores some 1500 labels at most.
49
%D
50
%D These commands accept all kind of inputs:
51
%D
52
%D \starttyping
53
%D \setuplabeltext [language] [labellabel=text]
54
%D \setuplabeltext [language] [labellabel=text,labellabel=text,...]
55
%D \setuplabeltext [labellabel=text]
56
%D \setuplabeltext [labellabel=text,labellabel=text,...]
57
%D \stoptyping
58
%D
59
%D The last two cases concern the current language.
60 61
\installcorenamespace
{
label
}
62 63
\let
\currentlabelcategory
\empty
64 65
\unexpanded
\def
\definelabelclass
66
{
\dodoubleempty
\lang_labels_define_class
}
67 68
\def
\lang_labels_define_class
[#
1
][#
2
]
%
69
{
\normalexpanded
70
{
\lang_labels_define_class_indeed
71
{
#
1
}
%
72
{
\ifsecondargument
#
2
\else
\zerocount
\fi
}
%
73
\expandafter\noexpand\csname
dogetupsome
#
1
text
\endcsname
74
\expandafter\noexpand\csname
#
1
language
\endcsname
75
\expandafter\noexpand\csname
dodogetupsome
#
1
text
\endcsname
76
\expandafter\noexpand\csname
left
#
1
text
\endcsname
77
\expandafter\noexpand\csname
right
#
1
text
\endcsname
78
\expandafter\noexpand\csname
#
1
texts
\endcsname
79
\expandafter\noexpand\csname
#
1
text
\endcsname
}}
80 81
% hm, not interfaced
82 83
\let
\thetextprefix
\empty
84 85
\unexpanded
\def
\lang_labels_define_class_indeed
#
1
#
2
#
3
#
4
#
5
#
6
#
7
#
8
#
9
%
86
{
\setuvalue
{
setup
#
1
text
}{
\protecttextprefixes
#
2
\def
\currenttextprefixclass
{
#
1
}
\dodoubleempty
\lang_labels_text_prefix_setup
}
%
87
\setuvalue
{
preset
#
1
text
}{
\protecttextprefixes
1
\def
\currenttextprefixclass
{
#
1
}
\dodoubleempty
\lang_labels_text_prefix_setup
}
%
88
\setuvalue
{
copy
#
1
text
}{
\protecttextprefixes
1
\def
\currenttextprefixclass
{
#
1
}
\dodoubleempty
\lang_labels_text_prefix_copy
}
%
89
\setuvalue
{
start
#
1
text
}{
\protecttextprefixes
1
\def
\currenttextprefixclass
{
#
1
}
\dotripleempty
\lang_labels_text_prefix_start
[#
1
]
}
%
90
\letvalue
{
stop
#
1
text
}
\relax
91
\def
#
4
{
\reallanguagetag
{
\defaultlanguage
\currentmainlanguage
}}
%
92
\ifnum
#
2
=
\plustwo
% used for math and tags
93
\def
#
3
{
#
5
#
4
}
%
94
\def
#
5
##
1
##
2
% ##1=language
95
{
\ifcsname
\??label
\currentlabelcategory
#
1
:
##
1
:
##
2
\endcsname
96
\lastnamedcs
97
\else\ifcsname
\??label
#
1
:
##
1
:
##
2
\endcsname
98
\lastnamedcs
99
% \else\ifcsname\??language#4\s!default\endcsname
100
% \expandafter#5\csname\??language#4\s!default\endcsname{##2}%
101
\else\ifcsname
\??language
##
1
\s!default
\endcsname
102
%\expandafter#5\csname\??language##1\s!default\endcsname{##2}%
103
\expandafter
#
5
\lastnamedcs
{
##
2
}
%
104
\else\ifcsname
\??label
\currentlabelcategory
#
1
:
##
2
\endcsname
105
\lastnamedcs
106
\else\ifcsname
\??label
#
1
:
##
2
\endcsname
107
\lastnamedcs
108
\else\ifcsname
\??label
\currentlabelcategory
#
1
:
\s!en
:
##
2
\endcsname
109
\lastnamedcs
110
\else\ifcsname
\??label
#
1
:
\s!en
:
##
2
\endcsname
111
\lastnamedcs
112
\else
113
##
2
%
114
\fi\fi\fi\fi\fi\fi\fi
}
%
115
\let
#
6
\gobbleoneargument
116
\let
#
7
\gobbleoneargument
117
\let
#
8
\gobbletwoarguments
118
\let
#
9
#
3
%
119
\else
120
\unexpanded
\def
#
3
{
#
5
#
4
}
%
121
\unexpanded
\def
#
5
##
1
##
2
%
122
{
\ifcsname
\??label
#
1
:
##
1
:
##
2
\endcsname
123
%\expandafter\let\expandafter\thetextprefix\csname\??label#1:##1:##2\endcsname
124
\expandafter\let\expandafter
\thetextprefix
\lastnamedcs
125
\else\ifcsname
\??language
#
4
\s!default
\endcsname
126
%\expandafter#5\csname\??language#4\s!default\endcsname{##2}%
127
\expandafter
#
5
\lastnamedcs
{
##
2
}
%
128
\else\ifcsname
\??label
#
1
:
##
2
\endcsname
129
%\expandafter\let\expandafter\thetextprefix\csname\??label#1:##2\endcsname
130
\expandafter\let\expandafter
\thetextprefix
\lastnamedcs
131
\else\ifcsname
\??label
#
1
:
\s!en
:
##
2
\endcsname
132
%\expandafter\let\expandafter\thetextprefix\csname\??label#1:\s!en:##2\endcsname
133
\expandafter\let\expandafter
\thetextprefix
\lastnamedcs
134
\else
135
\let
\thetextprefix
\dummytextprefix
136
\fi\fi\fi\fi
}
%
137
\unexpanded
\def
#
6
##
1
{
#
3
{
##
1
}
\expandafter
\flushleftlabelclass
\thetextprefix
}
%
138
\unexpanded
\def
#
7
##
1
{
#
3
{
##
1
}
\expandafter
\flushrightlabelclass
\thetextprefix
}
%
139
\unexpanded
\def
#
8
##
1
{
#
3
{
##
1
}
\expandafter
\flushbothlabelclass
\thetextprefix
}
% #2
140
\unexpanded
\def
#
9
##
1
{
#
3
{
##
1
}
\expandafter
\flushleftlabelclass
\thetextprefix
}
%
141
\fi
142
\appendtoks
143
\let
#
6
\firstofoneargument
% to be checked
144
\let
#
7
\firstofoneargument
% to be checked
145
\let
#
8
\firstofoneargument
% to be checked
146
\let
#
9
\firstofoneargument
% to be checked
147
\to
\everysimplifycommands
}
148 149
\let
\flushleftlabelclass
\firstoftwoarguments
150
\let
\flushrightlabelclass
\secondoftwoarguments
151
\def
\flushbothlabelclass
#
1
#
2
#
3
{
#
1
#
3
#
2
}
152
\def
\dummytextprefix
{
\empty\empty
}
153 154
%D \macros
155
%D {headtext, labeltext, leftlabeltext, rightlabeltext, labeltexts}
156
%D
157
%D Once defined, head and label texts can be called upon using:
158
%D
159
%D \showsetup{headtext}
160
%D \showsetup{labeltext}
161
%D
162
%D \macros
163
%D {presetheadtext,presetlabeltext}
164
%D
165
%D These macros enable us to automatically define head and label texts without
166
%D replacing predefined ones. They are internal macros.
167 168
\appendtoks
\let
\labellanguage\currentlanguage
\to
\everycurrentdate
169 170
\newconstant
\protecttextprefixes
171 172
\let
\currenttextprefixtag
\s!unknown
173
\let
\currenttextprefixclass
\s!unknown
174 175
\def
\lang_labels_text_prefix_start
[#
1
][#
2
][#
3
]
% class language name
176
{
\ifthirdargument
177
\edef
\currenttextprefixtag
{
\reallanguagetag
{
#
2
}}
%
178
\edef
\currenttextprefixname
{
#
3
}
%
179
\else
180
\edef
\currenttextprefixtag
{
\reallanguagetag
\currentmainlanguage
}
%
181
\edef
\currenttextprefixname
{
#
2
}
%
182
\fi
183
\grabuntil
{
stop
#
1
text
}
\lang_labels_text_prefix_start_indeed
}
184 185
\def
\lang_labels_text_prefix_start_indeed
#
1
% text (not special checking done here yet, only for long texts anyway)
186
{
\expandafter\edef\csname
\??label
\currenttextprefixclass
:
\currenttextprefixtag
:
\currenttextprefixname
\endcsname
%
187
{{
\clf_strip
{
#
1
}}
\empty
}}
188 189
\def
\lang_labels_text_prefix_setup
[#
1
][#
2
]
%
190
{
\ifsecondargument
191
\edef
\currenttextprefixtag
{
\reallanguagetag
{
#
1
}}
%
192
\processcommalist
[#
2
]
\lang_labels_text_prefix_setup_indeed
193
\else
194
\edef
\currenttextprefixtag
{
\reallanguagetag
\currentmainlanguage
}
%
195
\processcommalist
[#
1
]
\lang_labels_text_prefix_setup_indeed
196
\fi
}
197 198
\def
\lang_labels_text_prefix_setup_indeed
#
1
%
199
{
\lang_labels_text_prefix_assign
[#
1
]
}
200 201
\def
\lang_labels_text_prefix_assign
[#
1
=#
2
]
%
202
{
\lang_labels_text_prefix_assign_indeed
{
#
1
}
[#
2
,
,
]
}
203 204
\def
\lang_labels_text_prefix_assign_indeed
#
1
%
205
{
\ifcase
\protecttextprefixes
206
% no checking
207
\expandafter
\lang_labels_text_prefix_assign_yes
208
\or
209
% checking
210
\ifcsname
\??label
\currenttextprefixclass
:
\currenttextprefixtag
:
#
1
\endcsname
211
\expandafter\expandafter\expandafter
\lang_labels_text_prefix_assign_nop
212
\else
213
\expandafter\expandafter\expandafter
\lang_labels_text_prefix_assign_yes
214
\fi
215
\or
216
% simple assignment (a bit overkill but it fits in the whole)
217
\expandafter
\lang_labels_text_prefix_assign_dumb
218
\fi
{
#
1
}}
219 220
\let
\m_lang_labels_left
\empty
221
\let
\m_lang_labels_right
\empty
222 223
% \def\lang_labels_text_prefix_assign_yes#1[#2,#3,#4]%
224
% {\def\m_lang_labels_left {#2}% no longer an edef ... else \Word undefined expansion issues
225
% \def\m_lang_labels_right{#3}% no longer an edef ... else \Word undefined expansion issues
226
% \ifx\m_lang_labels_right\empty
227
% \ifx\m_lang_labels_left\empty
228
% \expandafter\def\csname\??label\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{\empty\empty}%
229
% \else
230
% \expandafter\def\csname\??label\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{{#2}\empty}%
231
% \fi
232
% \else
233
% \expandafter\def\csname\??label\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{{#2}{#3}}%
234
% \fi}
235
%
236
% how we love obscure efficicency ...
237 238
\def
\lang_labels_text_prefix_assign_yes
#
1
[#
2
,
#
3
,
#
4
]
%
239
{
\def
\m_lang_labels_left
{
#
2
}
% no longer an edef ... else \Word undefined expansion issues
240
\def
\m_lang_labels_right
{
#
3
}
% no longer an edef ... else \Word undefined expansion issues
241
\expandafter\def\csname
\??label
\currenttextprefixclass
:
\currenttextprefixtag
:
#
1
%
242
\ifx
\m_lang_labels_right
\empty
243
\ifx
\m_lang_labels_left
\empty
244
\endcsname
{
\empty\empty
}
%
245
\else
246
\endcsname
{{
#
2
}
\empty
}
%
247
\fi
248
\else
249
\endcsname
{{
#
2
}{
#
3
}}
%
250
\fi
}
251 252
\def
\lang_labels_text_prefix_assign_nop
#
1
[#
2
]
%
253
{}
254 255
\def
\lang_labels_text_prefix_assign_dumb
#
1
[#
2
,
#
3
]
%
256
{
\expandafter\def\csname
\??label
\currenttextprefixclass
:
\currenttextprefixtag
:
#
1
\endcsname
{
#
2
}}
257 258
\unexpanded
\def
\setlabeltextpair
#
1
#
2
#
3
#
4
#
5
% a fast one for usage at the Lua end
259
{
%\writestatus{!!!!}{#1:\reallanguagetag{#2}:#3}%
260
\expandafter\def\csname
\??label
#
1
:
\reallanguagetag
{
#
2
}
:
#
3
\endcsname
{{
#
4
}{
#
5
}}}
% class tag key left right
261 262
\def
\lang_labels_text_prefix_copy
[#
1
][#
2
]
%
263
{
\ifsecondargument
264
\edef
\currenttextprefixtag
{
\reallanguagetag
{
#
1
}}
%
265
\processcommalist
[#
2
]
\lang_labels_text_prefix_copy_indeed
266
\else
267
\edef
\currenttextprefixtag
{
\reallanguagetag
\currentmainlanguage
}
%
268
\processcommalist
[#
1
]
\lang_labels_text_prefix_copy_indeed
269
\fi
}
270 271
\def
\lang_labels_text_prefix_copy_indeed
#
1
%
272
{
\lang_labels_text_prefix_copy_pair
[#
1
]
}
273 274
\def
\lang_labels_text_prefix_copy_pair
[#
1
=#
2
]
%
275
{
\lang_labels_text_prefix_copy_pair_indeed
{
#
1
}
[#
2
,
,
]
}
276 277
% \def\lang_labels_text_prefix_copy_pair_indeed#1[#2,#3]%
278
% {\expandafter\let
279
% \csname\??label\currenttextprefixclass:\currenttextprefixtag:#1\expandafter\endcsname
280
% \csname\??label\currenttextprefixclass:\currenttextprefixtag:#2\endcsname}
281
%
282
% this delays the aliasing so that we can switch maillanguage in between
283 284
\def
\lang_labels_text_prefix_copy_pair_indeed
#
1
[#
2
,
#
3
]
%
285
{
\expandafter\edef\csname
\??label
\currenttextprefixclass
:
#
1
\endcsname
286
{{
\noexpand\csname
\??label
\currenttextprefixclass
:
\noexpand
\reallanguagetag
\noexpand
\currentmainlanguage
:
#
2
\endcsname
}{}}}
287 288
\definelabelclass
[
head
]
[
0
]
% titles
289
\definelabelclass
[
label
]
[
0
]
% texts
290
\definelabelclass
[
mathlabel
]
[
0
]
% functions
291
\definelabelclass
[
taglabel
]
[
2
]
% tags
292 293
\clf_definelabels
{
head
}{
titles
}
\s!true
\relax
294
\clf_definelabels
{
label
}{
texts
}
\s!true
\relax
295
\clf_definelabels
{
mathlabel
}{
functions
}
\s!false
\relax
296
\clf_definelabels
{
taglabel
}{
tags
}
\s!false
\relax
297 298
%D \macros
299
%D {translate}
300
%D
301
%D Sometimes macros contain language specific words that are to be typeset. Such
302
%D macros can be made (more) language independant by using:
303
%D
304
%D \showsetup{translate}
305
%D
306
%D like for instance:
307
%D
308
%D \starttyping
309
%D \translate[en=something,nl=iets]
310
%D \stoptyping
311
%D
312
%D which expands to {\em something} or {\em iets}, depending on de current language.
313 314
\installcorenamespace
{
translation
}
315 316
\unexpanded
\def
\translate
317
{
\dosingleempty
\lang_translate
}
318 319
\def
\lang_translate
[#
1
]
%
320
{
\getparameters
[
\??translation
][#
1
]
%
321
\ifcsname
\??translation
\currentlanguage
\endcsname
322
\lastnamedcs
323
\else\ifcsname
\??translation\s!en
\endcsname
324
\lastnamedcs
325
\else
326
[
translation
#
1
]
%
327
\fi\fi
}
328 329
%D When used without argument, the last defined values are used. This enables
330
%D repetitive use like
331
%D
332
%D \starttyping
333
%D \en \translate\ means \nl \translate
334
%D \stoptyping
335 336
%D \macros
337
%D {assigntranslation}
338
%D
339
%D This macro is a system macro, and can be used to assign a translation to a macro.
340
%D Its form is:
341
%D
342
%D \starttyping
343
%D \assigntranslation[en=something,nl=iets]\to\command
344
%D \stoptyping
345 346
\unexpanded
\def
\assigntranslation
[#
1
]
\to
#
2
% bad, this \to
347
{
\getparameters
[
\??translation
][#
1
]
%
348
\edef
#
2
{
\begincsname
\??translation
\currentlanguage
\endcsname
}}
349 350
%D \macros
351
%D {commalistsentence}
352
%D
353
%D Redone in \LUA:
354
%D
355
%D \startbuffer
356
%D \commalistsentence[aap,noot,mies]
357
%D \commalistsentence[aap,noot]
358
%D \commalistsentence[aap]
359
%D \commalistsentence[a,b,c]
360
%D \commalistsentence[a,b,c][{ \& },{ and }]
361
%D \commalistsentence[a,b,c][+,-]
362
%D \stopbuffer
363
%D
364
%D \typebuffer
365
%D
366
%D \startlines
367
%D \getbuffer
368
%D \stoplines
369 370
\unexpanded
\def
\commalistsentence
371
{
\dodoubleempty
\typo_helpers_concat_comma_list
}
372 373
\def
\typo_helpers_concat_comma_list
[#
1
][#
2
]
%
374
{
\clf_concatcommalist
375
text
{
#
1
}
%
376
separators
{
#
2
}
%
377
separator
{
\detokenize\expandafter
{
\normalexpanded
{
\labeltext
{
and
-
1
}}}}
%
378
last
{
\detokenize\expandafter
{
\normalexpanded
{
\labeltext
{
and
-
2
}}}}
%
379
\relax
}
380 381
\setuplabeltext
[
\s!nl
]
[
and
-
1
=
{{
,
}}
,
and
-
2
=
{{
en
}}
]
% 1, 2 en 3
382
\setuplabeltext
[
\s!en
]
[
and
-
1
=
{{
,
}}
,
and
-
2
=
{{
,
}}
]
% 1, 2, 3
383
\setuplabeltext
[
\s!de
]
[
and
-
1
=
{{
,
}}
,
and
-
2
=
{{
und
}}
]
% 1, 2 und 3
384
\setuplabeltext
[
\s!hr
]
[
and
-
1
=
{{
,
}}
,
and
-
2
=
{{
i
}}
]
% 1, 2 i 3
385 386
%D Goodie (handy at \LUA\ end):
387 388
\unexpanded
\def
\LABELTEXT
#
1
{
\WORD
{
\labeltext
{
#
1
}}}
% only for simple cases!
389 390
\protect
\endinput
391