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
35local textfile = "lang-imp-simpleascii-data.tsv"
36local datafile = "lang-imp-simpleascii-data.lua"
37local compfile = "lang-imp-simpleascii-data.lgz"
38
39local verbose = false
40local report = logs.reporter("simpleascii")
41
42if not context and lfs.isfile(textfile) then
43
44
45
46
47 local data = io.loaddata(textfile)
48 if data and data ~= "" then
49 local mapping = { }
50 for k, v in string.gmatch(data,"(%S+)[\t]*([^\n\r]-)[\n\r]") do
51 if k ~= "" and v ~= "" and k ~= v then
52 mapping[k] = v
53 end
54 end
55 if verbose then
56 table.save(datafile,mapping)
57 else
58 mapping = gzip.compress(table.fastserialize(mapping))
59 datafile = compfile
60 io.savedata(compfile,mapping)
61 end
62 report("data from %a saved in %a",textfile,datafile)
63 else
64 report("no data file %a",textfile)
65 end
66
67else
68
69 local mapping = false
70
71 if not verbose then
72 mapping = io.loaddata(resolvers.findfile(compfile) or "")
73 if mapping then
74 mapping = table.deserialize(gzip.decompress(mapping))
75 if mapping then
76 datafile = compfile
77 else
78 report("data file %a is corrupt",compfile)
79 end
80 end
81 end
82 if not mapping then
83 mapping = table.load(resolvers.findfile(datafile) or "")
84 end
85
86 if mapping then
87
88 report("data file %a loaded",datafile)
89
90
91
92
93
94 return {
95
96 name = "simple ascii",
97 version = "1.00",
98 comment = "Unicode to ASCII transliteration",
99 author = "Jairo A. del Rio & Hans Hagen",
100 copyright = "ConTeXt development team & whoever made this list",
101
102 transliterations = {
103 ["simple ascii"] = {
104 mapping = mapping
105 },
106 }
107
108 }
109
110 else
111 report("no data file %a",datafile)
112 end
113
114end
115 |