summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lang-lab.lua
blob: 1947616a99c755c4d6fd4e6856e16f15c77b8779 (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
if not modules then modules = { } end modules ['lang-lab'] = {
    version   = 1.001,
    comment   = "companion to lang-lab.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

--~ local function complete()
--~     local function process(what)
--~         for tag, data in next, what do
--~             for k, v in next, data.labels do
--~                 languages[k] = true
--~             end
--~         end
--~     end
--~     process(languages.labels.data.titles)
--~     process(languages.labels.data.texts)
--~     process(languages.labels.data.functions)
--~     process(languages.labels.data.tags)
--~     local function process(what)
--~         for tag, data in next, what do
--~             local labels = data.labels
--~             for k, v in next, languages do
--~                 if not labels[k] then
--~                     labels[k] = ""
--~                 end
--~             end
--~         end
--~     end
--~     process(languages.data.labels.titles)
--~     process(languages.data.labels.texts)
--~     process(languages.data.labels.functions)
--~     process(languages.data.labels.tags)
--~ end
--~
--~ local function strip(default)
--~     local function process(what)
--~         for tag, data in next, what do
--~             local labels = data.labels
--~             for k, v in next, labels do
--~                 if v == "" then
--~                     labels[k] = default
--~                 end
--~             end
--~         end
--~     end
--~     process(languages.data.labels.titles)
--~     process(languages.data.labels.texts)
--~     process(languages.data.labels.functions)
--~     process(languages.data.labels.tags)
--~ end
--~
--~ complete()
--~ strip(false)
--~ strip()

--~ table.print(languages.data.labels,"languages.data.labels",false,true,true)

-- this will move

local format, find = string.format, string.find
local next, rawget, type = next, rawget, type
local texsprint = tex.sprint
local prtcatcodes = tex.prtcatcodes

languages.labels = languages.labels or { }

local trace_labels = false  trackers.register("languages.labels", function(v) trace_labels = v end)

local report_labels = logs.reporter("languages","labels")

function languages.labels.define()
    local variables = interfaces.variables
    local data = languages.data.labels
    local function define(command,list,prefixed)
        if list then
            for tag, data in next, list do
                if data.hidden then
                    -- skip
                else
                    for language, text in next, data.labels do
                        if text == "" then
                            -- skip
                        elseif prefixed and rawget(variables,tag) then
                            if type(text) == "table" then
                                texsprint(prtcatcodes,format("\\%s[%s][\\v!%s={{%s},{%s}}]",command,language,tag,text[1],text[2]))
                            else
                                texsprint(prtcatcodes,format("\\%s[%s][\\v!%s={{%s},}]",command,language,tag,text))
                            end
                        else
                            if type(text) == "table" then
                                texsprint(prtcatcodes,format("\\%s[%s][%s={{%s},{%s}}]",command,language,tag,text[1],text[2]))
                            else
                                texsprint(prtcatcodes,format("\\%s[%s][%s={{%s},}]",command,language,tag,text))
                            end
                        end
                        if trace_labels then
                            if type(text) == "table" then
                                report_labels("language '%s', defining label '%s' as '%s' and '%s'",language,tag,text[1],text[2])
                            else
                                report_labels("language '%s', defining label '%s' as '%s'",language,tag,text)
                            end
                        end
                    end
                end
            end
        end
    end
    define("setupheadtext", data.titles, true)
    define("setuplabeltext", data.texts, true)
    define("setupmathlabeltext", data.functions)
    define("setuptaglabeltext", data.tags)
end

--~ function languages.labels.check()
--~     for category, list in next, languages.data.labels do
--~         for tag, specification in next, list do
--~             for language, text in next, specification.labels do
--~                 if type(text) == "string" and find(text,",") then
--~                     report_labels("label with comma: category '%s', language '%s', tag '%s', text '%s'",
--~                         category, language, tag, text)
--~                 end
--~             end
--~         end
--~     end
--~ end
--~
--~ languages.labels.check()