Skip to content

Commit 8e129d3

Browse files
committed
tools/script_manager - added translated folder names.
cleaned up metadata handling (trimmed whitespace and comments) fixed bug with folder names partially matching other folder names
1 parent d123634 commit 8e129d3

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

tools/script_manager.lua

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ sm.event_registered = false
132132

133133
sm.widgets = {}
134134
sm.folders = {}
135+
sm.translated_folders = {}
135136

136137
-- set log level for functions
137138

@@ -364,8 +365,9 @@ end
364365
local function string_trim(str)
365366
local old_log_level = set_log_level(sm.log_level)
366367

367-
local result = string.gsub(str, "^%s+", "")
368-
result = string.gsub(result, "%s+$", "")
368+
local result = string.gsub(str, "^%s+", "") -- trim leading spaces
369+
result = string.gsub(result, "%s+$", "") -- trim trailing spaces
370+
result = string.gsub(result, ",?%s+%-%-.+$", "") -- trim trailing comma and comments
369371

370372
restore_log_level(old_log_level)
371373
return result
@@ -387,11 +389,42 @@ end
387389
-- script handling
388390
------------------
389391

392+
local function is_folder_known(folder_table, name)
393+
local match = false
394+
395+
for _, folder_name in ipairs(folder_table) do
396+
if name == folder_name then
397+
match = true
398+
end
399+
end
400+
401+
return match
402+
end
403+
404+
local function find_translated_name(folder)
405+
local translated_name = nil
406+
407+
if folder == "contrib" then
408+
translated_name = _("contributed")
409+
elseif folder == "examples" then
410+
translated_name = _("examples")
411+
elseif folder == "official" then
412+
translated_name = _("official")
413+
elseif folder == "tools" then
414+
translated_name = _("tools")
415+
else
416+
translated_name = _(folder) -- in case we get lucky and the string got translated elsewhere
417+
end
418+
419+
return translated_name
420+
end
421+
390422
local function add_script_folder(folder)
391423
local old_log_level = set_log_level(sm.log_level)
392424

393-
if #sm.folders == 0 or not string.match(du.join(sm.folders, " "), ds.sanitize_lua(folder)) then
425+
if #sm.folders == 0 or not is_folder_known(sm.folders, folder) then
394426
table.insert(sm.folders, folder)
427+
table.insert(sm.translated_folders, find_translated_name(folder))
395428
sm.scripts[folder] = {}
396429
log.msg(log.debug, "created folder " .. folder)
397430
end
@@ -427,6 +460,7 @@ local function get_script_metadata(script)
427460
log.msg(log.debug, "splitting line " .. lines[i])
428461
local parts = du.split(lines[i], " = ")
429462
parts[1] = string_trim(parts[1])
463+
parts[2] = string_trim(parts[2])
430464
log.msg(log.debug, "got value " .. parts[1] .. " and data " .. parts[2])
431465
if string.match(parts[2], "%_%(") then
432466
parts[2] = _(string_dequote(string_dei18n(parts[2])))
@@ -1378,10 +1412,10 @@ sm.widgets.folder_selector = dt.new_widget("combobox"){
13781412
changed_callback = function(self)
13791413
if sm.run then
13801414
pref_write("folder_selector", "integer", self.selected)
1381-
change_folder(self.value)
1415+
change_folder(sm.folders[self.selected])
13821416
end
13831417
end,
1384-
table.unpack(sm.folders),
1418+
table.unpack(sm.translated_folders),
13851419
}
13861420

13871421
-- a script "button" consists of:

0 commit comments

Comments
 (0)