3 local concat = table.concat
4 local insert = table.insert
5 local sprintf = string.format
8 local minetest_example_header = [[
9 # This file contains a list of all available settings and their default value for minetest.conf
11 # By default, all the settings are commented and not functional.
12 # Uncomment settings by removing the preceding #.
14 # minetest.conf is read by default from:
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".
20 # Further documentation:
21 # http://wiki.minetest.net/
25 local group_format_template = [[
29 # spread = (%s, %s, %s),
39 local function create_minetest_conf_example()
40 local result = { minetest_example_header }
41 for _, entry in ipairs(settings) do
42 if entry.type == "category" then
43 if entry.level == 0 then
44 insert(result, "#\n# " .. entry.name .. "\n#\n\n")
46 insert(result, rep("#", entry.level))
47 insert(result, "# " .. entry.name .. "\n\n")
50 local group_format = false
51 if entry.noise_params and entry.values then
52 if entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then
56 if entry.comment ~= "" then
57 for _, comment_line in ipairs(entry.comment:split("\n", true)) do
58 if comment_line == "" then
61 insert(result, "# " .. comment_line .. "\n")
65 insert(result, "# type: " .. entry.type)
67 insert(result, " min: " .. entry.min)
70 insert(result, " max: " .. entry.max)
72 if entry.values and entry.noise_params == nil then
73 insert(result, " values: " .. concat(entry.values, ", "))
75 if entry.possible then
76 insert(result, " possible values: " .. concat(entry.possible, ", "))
79 if group_format == true then
80 local flags = entry.values[10]
84 insert(result, sprintf(group_format_template, entry.name, entry.values[1],
85 entry.values[2], entry.values[3], entry.values[4], entry.values[5],
86 entry.values[6], entry.values[7], entry.values[8], entry.values[9],
90 if entry.default ~= "" then
91 append = " " .. entry.default
93 insert(result, sprintf("# %s =%s\n\n", entry.name, append or ""))
100 local translation_file_header = [[
101 // This file is automatically generated
102 // It contains a bunch of fake gettext calls, to tell xgettext about the strings in config files
103 // To update it, refer to the bottom of builtin/mainmenu/dlg_settings_advanced.lua
107 local function create_translation_file()
108 local result = { translation_file_header }
109 for _, entry in ipairs(settings) do
110 if entry.type == "category" then
111 insert(result, sprintf("\tgettext(%q);", entry.name))
113 if entry.readable_name then
114 insert(result, sprintf("\tgettext(%q);", entry.readable_name))
116 if entry.comment ~= "" then
117 local comment_escaped = entry.comment:gsub("\n", "\\n")
118 comment_escaped = comment_escaped:gsub("\"", "\\\"")
119 insert(result, "\tgettext(\"" .. comment_escaped .. "\");")
123 insert(result, "}\n")
124 return concat(result, "\n")
127 local file = assert(io.open("minetest.conf.example", "w"))
128 file:write(create_minetest_conf_example())
131 file = assert(io.open("src/settings_translation_file.cpp", "w"))
132 -- If 'minetest.conf.example' appears in the 'bin' folder, the line below may have to be
133 -- used instead. The file will also appear in the 'bin' folder.
134 --file = assert(io.open("settings_translation_file.cpp", "w"))
135 file:write(create_translation_file())