summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lang-lab.mkiv
blob: 025958ade6a034b6c1a374082203d165c3f84c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%D \module
%D   [       file=lang-lab,
%D        version=1997.08.27,
%D          title=\CONTEXT\ Language Macros,
%D       subtitle=Labels,
%D         author=Hans Hagen / Tobias Burnus,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Language Macros / Labels}

\registerctxluafile{lang-lab}{1.001}
\registerctxluafile{lang-txt}{1.001}

\unprotect

%C The UPPERCASE variants are obsolete as we can now use \WORD
%C in an non-interfering way.

%D In this module we deal with language dependant labels and
%D prefixes, like in {\em Figure~12} and {\em Chapter 1}. In
%D this file we set the default values. Users can easily
%D overrule these.
%D
%D This module is dedicated to the grandfather of Tobias
%D Burnus, who's extensive languages oriented library helped us
%D a lot in finding the right translations. All those labels
%D are collected in files that reflect their common ancestor.
%D
%D Not all languages can be satisfied with the labeling
%D mechanism as provided here. Chinese for instance put a label
%D in front as well as after a part number. This is why the
%D current implementation of labels supports two labels too.

\ifdefined\simplifiedcommands \else \newtoks\simplifiedcommands \fi
\ifdefined\Word               \else \let\Word\relax             \fi

%D \macros
%D   {setupheadtext, setuplabeltext}
%D
%D First we present some macros that deal with what we will
%D call head and label texts. Such texts are defines by:
%D
%D \showsetup{setupheadtext}
%D \showsetup{setuplabeltext}
%D
%D A regular \CONTEXT\ stores some 1500 labels at most.
%D
%D These commands accept all kind of inputs:
%D
%D \starttyping
%D \setuplabeltext [language] [labellabel=text]
%D \setuplabeltext [language] [labellabel=text,labellabel=text,...]
%D \setuplabeltext            [labellabel=text]
%D \setuplabeltext            [labellabel=text,labellabel=text,...]
%D \stoptyping
%D
%D The last two cases concern the current language.

\def\definelabelclass
  {\dodoubleempty\dodefinelabelclass}

\def\dodefinelabelclass[#1][#2]%
  {\normalexpanded
     {\noexpand\dododefinelabelclass
        {#1}%
        {\ifsecondargument#2\else\zerocount\fi}%
        \expandafter\noexpand\csname   dogetupsome#1text\endcsname
        \expandafter\noexpand\csname          #1language\endcsname
        \expandafter\noexpand\csname dodogetupsome#1text\endcsname
        \expandafter\noexpand\csname          left#1text\endcsname
        \expandafter\noexpand\csname         right#1text\endcsname
        \expandafter\noexpand\csname             #1texts\endcsname
        \expandafter\noexpand\csname              #1text\endcsname}}

\let\currentlabelcategory\empty

\def\dododefinelabelclass#1#2#3#4#5#6#7#8#9%
  {\setuvalue{setup#1text}{\protecttextprefixes#2\def\currenttextprefixclass{#1}\dodoubleempty\dosetupsometextprefix}%
   \setuvalue{preset#1text}{\protecttextprefixes1\def\currenttextprefixclass{#1}\dodoubleempty\dosetupsometextprefix}%
   \def#4{\reallanguagetag{\defaultlanguage\currentmainlanguage}}%
   \ifnum#2=\plustwo
     \def#3{#5#4}%
%      \def#5##1##2% ##1=language
%        {\ifcsname\??ml:#1:##1:##2\endcsname
%           \csname\??ml:#1:##1:##2\endcsname
%         \else\ifcsname\??la#4\s!default\endcsname
%           \expandafter#5\csname\??la#4\s!default\endcsname{##2}%
%         \else\ifcsname\??ml:#1:##2\endcsname
%           \csname\??ml:#1:##2\endcsname
%         \else\ifcsname\??ml:#1:\s!en:##2\endcsname
%           \csname\??ml:#1:\s!en:##2\endcsname
%         \else
%           ##2%
%         \fi\fi\fi\fi}%
     \def#5##1##2% ##1=language
       {\ifcsname\??ml:\currentlabelcategory#1:##1:##2\endcsname
          \csname\??ml:\currentlabelcategory#1:##1:##2\endcsname
        \else\ifcsname\??ml:#1:##1:##2\endcsname
          \csname\??ml:#1:##1:##2\endcsname
        \else\ifcsname\??la#4\s!default\endcsname
          \expandafter#5\csname\??la#4\s!default\endcsname{##2}%
        \else\ifcsname\??ml:\currentlabelcategory#1:##2\endcsname
          \csname\??ml:\currentlabelcategory#1:##2\endcsname
        \else\ifcsname\??ml:#1:##2\endcsname
          \csname\??ml:#1:##2\endcsname
        \else\ifcsname\??ml:\currentlabelcategory#1:\s!en:##2\endcsname
          \csname\??ml:\currentlabelcategory#1:\s!en:##2\endcsname
        \else\ifcsname\??ml:#1:\s!en:##2\endcsname
          \csname\??ml:#1:\s!en:##2\endcsname
        \else
          ##2%
        \fi\fi\fi\fi\fi\fi\fi}%
     \let#6\gobbleoneargument
     \let#7\gobbleoneargument
     \let#8\gobbletwoarguments
     \let#9#3%
   \else
     \unexpanded\def#3{#5#4}%
     \unexpanded\def#5##1##2%
       {\ifcsname\??ml:#1:##1:##2\endcsname
          \expandafter\let\expandafter\thetextprefix\csname\??ml:#1:##1:##2\endcsname
        \else\ifcsname\??la#4\s!default\endcsname
          \expandafter#5\csname\??la#4\s!default\endcsname{##2}%
        \else\ifcsname\??ml:#1:##2\endcsname
          \expandafter\let\expandafter\thetextprefix\csname\??ml:#1:##2\endcsname
        \else\ifcsname\??ml:#1:\s!en:##2\endcsname
          \expandafter\let\expandafter\thetextprefix\csname\??ml:#1:\s!en:##2\endcsname
        \else
          \let\thetextprefix\dummytextprefix
        \fi\fi\fi\fi}%
     \unexpanded\def#6##1{#3{##1}\expandafter\flushleftlabelclass \thetextprefix}%
     \unexpanded\def#7##1{#3{##1}\expandafter\flushrightlabelclass\thetextprefix}%
     \unexpanded\def#8##1{#3{##1}\expandafter\flushbothlabelclass \thetextprefix}% #2
     \unexpanded\def#9##1{#3{##1}\expandafter\flushleftlabelclass \thetextprefix}%
   \fi
   \appendtoks
     \let#6\firstofoneargument % to be checked
     \let#7\firstofoneargument % to be checked
     \let#8\firstofoneargument % to be checked
     \let#9\firstofoneargument % to be checked
   \to \simplifiedcommands
  }

\let\flushleftlabelclass \firstoftwoarguments
\let\flushrightlabelclass\secondoftwoarguments
\def\flushbothlabelclass #1#2#3{#1#3#2}
\def\dummytextprefix     {\empty\empty}

%D \macros
%D   {headtext,
%D    labeltext, leftlabeltext, rightlabeltext, labeltexts,
%D    LABELTEXT, LEFTLABELTEXT, RIGHTLABELTEXT, LABELTEXTS}
%D
%D Once defined, head and label texts can be called upon using:
%D
%D \showsetup{headtext}
%D \showsetup{labeltext}
%D
%D The latter one has an upcased alternative \type{\LABELTEXT}.
%D
%D \macros
%D   {presetheadtext,presetlabeltext}
%D
%D These macros enable us to automatically define head and label
%D texts without replacing predefined ones. They are internal macros.

\definelabelclass [head]      [0] % titles
\definelabelclass [label]     [0] % texts
\definelabelclass [mathlabel] [0] % functions
\definelabelclass [taglabel]  [2] % tags

\appendtoks \let\labellanguage\currentlanguage \to \everycurrentdate

\newconstant\protecttextprefixes

\let\currenttextprefixtag  \s!unknown
\let\currenttextprefixclass\s!unknown

\def\dosetupsometextprefix[#1][#2]%
  {\ifsecondargument
     \edef\currenttextprefixtag{\reallanguagetag{#1}}%
     \processcommalist[#2]\dodosetupsometextprefix
   \else
     \edef\currenttextprefixtag{\reallanguagetag\currentmainlanguage}%
     \processcommalist[#1]\dodosetupsometextprefix
   \fi}

\def\dodosetupsometextprefix#1%
  {\dododosetupsometextprefix[#1]}

\def\dododosetupsometextprefix[#1=#2]%
  {\doassignsometextprefix{#1}[#2,,]}

\def\doassignsometextprefix#1%
  {\ifcase\protecttextprefixes
     % no checking
     \expandafter\doassignsometextprefixyes
   \or
     % checking
     \ifcsname\??ml:\currenttextprefixclass:\currenttextprefixtag:#1\endcsname
       \expandafter\expandafter\expandafter\doassignsometextprefixnop
     \else
       \expandafter\expandafter\expandafter\doassignsometextprefixyes
     \fi
   \or
     % simple assignment (a bit overkill but it fits in the whole)
     \expandafter\doassignsometextprefixdumb
   \fi{#1}}

\def\doassignsometextprefixyes#1[#2,#3,#4]%
  {\edef\!!stringa{#2}%
   \edef\!!stringb{#3}%
   \ifx\!!stringb\empty
     \ifx\!!stringa\empty
       \expandafter\def\csname\??ml:\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{\empty\empty}%
     \else
       \expandafter\def\csname\??ml:\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{{#2}\empty}%
     \fi
   \else
     \expandafter\def\csname\??ml:\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{{#2}{#3}}%
   \fi}

\def\doassignsometextprefixnop#1[#2]%
  {}

\def\doassignsometextprefixdumb#1[#2,#3]%
  {\expandafter\def\csname\??ml:\currenttextprefixclass:\currenttextprefixtag:#1\endcsname{#2}}

%D \macros
%D   {translate}
%D
%D Sometimes macros contain language specific words that are to
%D be typeset. Such macros can be made (more) language
%D independant by using:
%D
%D \showsetup{translate}
%D
%D like for instance:
%D
%D \starttyping
%D \translate[en=something,nl=iets]
%D \stoptyping
%D
%D which expands to {\em something} or {\em iets}, depending on
%D de current language.

\def\dotranslate[#1]%
  {\getparameters[\??lg][#1]%
   \ifcsname\??lg\currentlanguage\endcsname
     \csname\??lg\currentlanguage\endcsname
   \else\ifcsname\??lg\s!en\endcsname
     \csname\??lg\s!en\endcsname
   \else
     [translation #1]%
   \fi\fi}

\unexpanded\def\translate
  {\dosingleempty\dotranslate}

%D When used without argument, the last defined values are
%D used. This enables repetitive use like
%D
%D \starttyping
%D \en \translate\ means \nl \translate
%D \stoptyping

%D \macros
%D   {assigntranslation}
%D
%D This macro is a system macro, and can be used to assign a
%D translation to a macro. Its form is:
%D
%D \starttyping
%D \assigntranslation[en=something,nl=iets]\to\command
%D \stoptyping

\def\assigntranslation[#1]\to#2%
  {\getparameters[\??lg][#1]%
   \edef#2{\csname\??lg\currentlanguage\endcsname}}

%D Now we load the labels:

\ifdefined\sixperemspace \else \def\sixperemspace{ } \fi % we could embed 0x2006 but it does not show up in a editor

%D Now we can load the labels:

\ctxlua{languages.labels.define()}

\protect \endinput