]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/generate_from_settingtypes.lua
Mainmenu: Brighter text colours for readability
[dragonfireclient.git] / builtin / mainmenu / generate_from_settingtypes.lua
1 local settings = ...
2
3 local concat = table.concat
4 local insert = table.insert
5 local sprintf = string.format
6 local rep = string.rep
7
8 local minetest_example_header = [[
9 #    This file contains a list of all available settings and their default value for minetest.conf
10
11 #    By default, all the settings are commented and not functional.
12 #    Uncomment settings by removing the preceding #.
13
14 #    minetest.conf is read by default from:
15 #    ../minetest.conf
16 #    ../../minetest.conf
17 #    Any other path can be chosen by passing the path as a parameter
18 #    to the program, eg. "minetest.exe --config ../minetest.conf.example".
19
20 #    Further documentation:
21 #    http://wiki.minetest.net/
22
23 ]]
24
25 local function create_minetest_conf_example()
26         local result = { minetest_example_header }
27         for _, entry in ipairs(settings) do
28                 if entry.type == "category" then
29                         if entry.level == 0 then
30                                 insert(result, "#\n# " .. entry.name .. "\n#\n\n")
31                         else
32                                 insert(result, rep("#", entry.level))
33                                 insert(result, "# " .. entry.name .. "\n\n")
34                         end
35                 else
36                         if entry.comment ~= "" then
37                                 for _, comment_line in ipairs(entry.comment:split("\n", true)) do
38                                         insert(result, "#    " .. comment_line .. "\n")
39                                 end
40                         end
41                         insert(result, "#    type: " .. entry.type)
42                         if entry.min then
43                                 insert(result, " min: " .. entry.min)
44                         end
45                         if entry.max then
46                                 insert(result, " max: " .. entry.max)
47                         end
48                         if entry.values then
49                                 insert(result, " values: " .. concat(entry.values, ", "))
50                         end
51                         if entry.possible then
52                                 insert(result, " possible values: " .. entry.possible:gsub(",", ", "))
53                         end
54                         insert(result, "\n")
55                         local append
56                         if entry.default ~= "" then
57                                 append = " " .. entry.default
58                         end
59                         insert(result, sprintf("# %s =%s\n\n", entry.name, append or ""))
60                 end
61         end
62         return concat(result)
63 end
64
65 local translation_file_header = [[
66 // This file is automatically generated
67 // It conatins a bunch of fake gettext calls, to tell xgettext about the strings in config files
68 // To update it, refer to the bottom of builtin/mainmenu/dlg_settings_advanced.lua
69
70 fake_function() {]]
71
72 local function create_translation_file()
73         local result = { translation_file_header }
74         for _, entry in ipairs(settings) do
75                 if entry.type == "category" then
76                         insert(result, sprintf("\tgettext(%q);", entry.name))
77                 else
78                         if entry.readable_name then
79                                 insert(result, sprintf("\tgettext(%q);", entry.readable_name))
80                         end
81                         if entry.comment ~= "" then
82                                 local comment_escaped = entry.comment:gsub("\n", "\\n")
83                                 comment_escaped = comment_escaped:gsub("\"", "\\\"")
84                                 insert(result, "\tgettext(\"" .. comment_escaped .. "\");")
85                         end
86                 end
87         end
88         insert(result, "}\n")
89         return concat(result, "\n")
90 end
91
92 local file = assert(io.open("minetest.conf.example", "w"))
93 file:write(create_minetest_conf_example())
94 file:close()
95
96 file = assert(io.open("src/settings_translation_file.cpp", "w"))
97 file:write(create_translation_file())
98 file:close()
99