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 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")
32 insert(result, rep("#", entry.level))
33 insert(result, "# " .. entry.name .. "\n\n")
36 if entry.comment ~= "" then
37 for _, comment_line in ipairs(entry.comment:split("\n", true)) do
38 insert(result, "# " .. comment_line .. "\n")
41 insert(result, "# type: " .. entry.type)
43 insert(result, " min: " .. entry.min)
46 insert(result, " max: " .. entry.max)
49 insert(result, " values: " .. concat(entry.values, ", "))
51 if entry.possible then
52 insert(result, " possible values: " .. entry.possible:gsub(",", ", "))
56 if entry.default ~= "" then
57 append = " " .. entry.default
59 insert(result, sprintf("# %s =%s\n\n", entry.name, append or ""))
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
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))
78 if entry.readable_name then
79 insert(result, sprintf("\tgettext(%q);", entry.readable_name))
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 .. "\");")
89 return concat(result, "\n")
92 local file = assert(io.open("minetest.conf.example", "w"))
93 file:write(create_minetest_conf_example())
96 file = assert(io.open("src/settings_translation_file.cpp", "w"))
97 file:write(create_translation_file())