-
Notifications
You must be signed in to change notification settings - Fork 18
/
init.typ
123 lines (105 loc) · 2.87 KB
/
init.typ
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
#let _prefix-csv(path, delimiter: ",") = {
/// Load a CSV file with pre- or postfixes.
/// - `path`: Path of the CSV file.
/// - `delimiter`: Passed to the `csv` function.
let array = csv(path, delimiter: delimiter)
let symbols = (:)
let symbols-short = (:)
for line in array {
symbols.insert(lower(line.at(0)), line.at(2))
symbols-short.insert(line.at(1), line.at(2))
}
(symbols, symbols-short)
}
#let _postfix-csv(path, delimiter: ",") = {
/// Load a CSV file with pre- or postfixes.
/// - `path`: Path of the CSV file.
/// - `delimiter`: Passed to the `csv` function.
let array = csv(path, delimiter: delimiter)
let dict = (:)
for line in array {
dict.insert(lower(line.at(0)), line.at(1))
}
dict
}
#let _unit-csv(path, delimiter: ",") = {
/// Load a CSV file with units.
/// - `path`: Path of the CSV file.
/// - `delimiter`: Passed to the `csv` function.
let array = csv(path, delimiter: delimiter)
let units = (:)
let units-short = (:)
let units-space = (:)
let units-short-space = (:)
for line in array {
units.insert(lower(line.at(0)), line.at(2))
units-short.insert(line.at(1), line.at(2))
if line.at(3) == "false" or line.at(3) == "0" {
units-space.insert(lower(line.at(0)), false)
units-short-space.insert(line.at(1), false)
} else {
units-space.insert(lower(line.at(0)), true)
units-short-space.insert(line.at(1), true)
}
}
(units, units-short, units-space, units-short-space)
}
#let _postfixes = _postfix-csv("postfixes.csv")
#let _add-money-units(data) = {
let (units, units-short, units-space, units-short-space) = data
let array = csv("money.csv", delimiter: ",")
for line in array {
units.insert(lower(line.at(0)), line.at(2))
units-short.insert(line.at(1), line.at(2))
if line.at(3) == "false" or line.at(3) == "0" {
units-space.insert(lower(line.at(0)), false)
units-short-space.insert(line.at(1), false)
} else {
units-space.insert(lower(line.at(0)), true)
units-short-space.insert(line.at(1), true)
}
}
(units, units-short, units-space, units-short-space)
}
#let _lang-db = state(
"lang-db",
(
"en": (
"units": (_add-money-units(_unit-csv("units-en.csv"))),
"prefixes": (_prefix-csv("prefixes-en.csv")),
),
"ru": (
"units": (_add-money-units(_unit-csv("units-ru.csv"))),
"prefixes": (_prefix-csv("prefixes-ru.csv")),
),
),
)
#let _get-language() = {
let lang = text.lang
let data = _lang-db.get()
if lang in data {
lang
} else {
"en"
}
}
// get prefixes
#let _prefixes() = {
let lang = text.lang
let data = _lang-db.get()
if lang in data {
data.at(lang).prefixes
} else {
data.en.prefixes
}
}
// get units
#let _units() = {
let lang = text.lang
let data = _lang-db.get()
if lang in data {
data.at(lang).units
} else {
data.en.units
}
}