Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of hidden settings in settings_translation_file.cpp #13984

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ local function load_settingtypes()
content = {},
}

if page.title:sub(1, 5) ~= "Hide:" then
page = add_page(page)
end
page = add_page(page)
elseif entry.level == 2 then
ensure_page_started()
page.content[#page.content + 1] = {
Expand Down
14 changes: 5 additions & 9 deletions builtin/mainmenu/settings/generate_from_settingtypes.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local settings = ...

local concat = table.concat
local insert = table.insert
local sprintf = string.format
Expand Down Expand Up @@ -36,7 +34,7 @@ local group_format_template = [[

]]

local function create_minetest_conf_example()
local function create_minetest_conf_example(settings)
local result = { minetest_example_header }
for _, entry in ipairs(settings) do
if entry.type == "category" then
Expand Down Expand Up @@ -108,14 +106,11 @@ local translation_file_header = [[

fake_function() {]]

local function create_translation_file()
local function create_translation_file(settings)
local result = { translation_file_header }
for _, entry in ipairs(settings) do
if entry.type == "category" then
insert(result, sprintf("\tgettext(%q);", entry.name))
elseif entry.type == "key" then --luacheck: ignore
-- Neither names nor descriptions of keys are used since we have a
-- dedicated menu for them.
else
if entry.readable_name then
insert(result, sprintf("\tgettext(%q);", entry.readable_name))
Expand All @@ -132,12 +127,13 @@ local function create_translation_file()
end

local file = assert(io.open("minetest.conf.example", "w"))
file:write(create_minetest_conf_example())
file:write(create_minetest_conf_example(settingtypes.parse_config_file(true, false)))
file:close()

file = assert(io.open("src/settings_translation_file.cpp", "w"))
-- If 'minetest.conf.example' appears in the 'bin' folder, the line below may have to be
-- used instead. The file will also appear in the 'bin' folder.
--file = assert(io.open("settings_translation_file.cpp", "w"))
file:write(create_translation_file())
-- We don't want hidden settings to be translated, so we set read_all to false.
file:write(create_translation_file(settingtypes.parse_config_file(false, false)))
file:close()
2 changes: 1 addition & 1 deletion builtin/mainmenu/settings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ dofile(path .. DIR_DELIM .. "dlg_settings.lua")
-- For RUN_IN_PLACE the generated files may appear in the 'bin' folder.
-- See comment and alternative line at the end of 'generate_from_settingtypes.lua'.

-- assert(loadfile(path .. DIR_DELIM .. "generate_from_settingtypes.lua"))(settingtypes.parse_config_file(true, false))
-- dofile(path .. DIR_DELIM .. "generate_from_settingtypes.lua")
27 changes: 26 additions & 1 deletion builtin/mainmenu/settings/settingtypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,37 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
-- category
local stars, category = line:match("^%[([%*]*)([^%]]+)%]$")
if category then
local category_level = stars:len() + base_level

if settings.current_hide_level then
if settings.current_hide_level < category_level then
-- Skip this category, it's inside a hidden category.
return
else
-- The start of this category marks the end of a hidden category.
settings.current_hide_level = nil
end
end

if not read_all and category:sub(1, 5) == "Hide:" then
-- This category is hidden.
settings.current_hide_level = category_level
return
end

table.insert(settings, {
name = category,
level = stars:len() + base_level,
level = category_level,
type = "category",
})
return
end

if settings.current_hide_level then
-- Ignore this line, we're inside a hidden category.
return
end

-- settings
local first_part, name, readable_name, setting_type = line:match("^"
-- this first capture group matches the whole first part,
Expand Down Expand Up @@ -349,6 +372,7 @@ end
local function parse_single_file(file, filepath, read_all, result, base_level, allow_secure)
-- store this helper variable in the table so it's easier to pass to parse_setting_line()
result.current_comment = {}
result.current_hide_level = nil

local line = file:read("*line")
while line do
Expand All @@ -360,6 +384,7 @@ local function parse_single_file(file, filepath, read_all, result, base_level, a
end

result.current_comment = nil
result.current_hide_level = nil
end


Expand Down