updated script_manager and executable_manager to use darktable

translation facilities.  Changed translatable messages with
arguments to use string.format for one complete string versus snippets.

Removed gen_i18n_mo since we will be using darktable's translation
facilities and there's no need to generate lua specific mo files.
This commit is contained in:
Bill Ferguson
2024-01-19 15:24:56 -05:00
parent 3b8e802e42
commit f9fe33f930
3 changed files with 22 additions and 134 deletions

View File

@@ -56,14 +56,12 @@ local dtsys = require "lib/dtutils.system"
local log = require "lib/dtutils.log"
local debug = require "darktable.debug"
local gettext = dt.gettext
-- set up translation
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("script_manager",dt.configuration.config_dir.."/lua/locale/")
local gettext = dt.gettext.gettext
local function _(msgid)
return gettext.dgettext("script_manager", msgid)
return gettext(msgid)
end
-- api check
@@ -369,7 +367,7 @@ local function get_script_doc(script)
-- assume that the second block comment is the documentation
description = string.match(content, "%-%-%[%[.-%]%].-%-%-%[%[(.-)%]%]")
else
log.msg(log.error, _("Cant read from " .. script))
log.msg(log.error, "Cant read from " .. script)
end
if description then
restore_log_level(old_log_level)
@@ -392,7 +390,7 @@ local function activate(script)
script_manager_running_script = nil
if status then
pref_write(script.script_name, "bool", true)
log.msg(log.screen, _("Loaded ") .. script.script_name)
log.msg(log.screen, string.format(_("Loaded %s"), script.script_name))
script.running = true
if err ~= true then
log.msg(log.debug, "got lib data")
@@ -404,7 +402,7 @@ local function activate(script)
script.data = nil
end
else
log.msg(log.screen, script.script_name .. _(" failed to load"))
log.msg(log.screen, string.format(_("%s failed to load"), script.script_name))
log.msg(log.error, "Error loading " .. script.script_name)
log.msg(log.error, "Error message: " .. err)
end
@@ -443,11 +441,11 @@ local function deactivate(script)
script.running = false
end
log.msg(log.info, "turned off " .. script.script_name)
log.msg(log.screen, script.name .. _(" stopped"))
log.msg(log.screen, string.format(_("%s stopped"), script.name))
else
script.running = false
log.msg(log.info, "setting " .. script.script_name .. " to not start")
log.msg(log.screen, script.name .. _(" will not start when darktable is restarted"))
log.msg(log.screen, string.format(_("%s will not start when darktable is restarted"), script.name))
end
restore_log_level(old_log_level)
end
@@ -515,7 +513,7 @@ local function scan_scripts(script_dir)
if dt.configuration.running_os == "windows" then
find_cmd = "dir /b/s \"" .. script_dir .. "\\*.lua\" | sort"
end
log.msg(log.debug, _("find command is ") .. find_cmd)
log.msg(log.debug, "find command is " .. find_cmd)
-- scan the scripts
local output = io.popen(find_cmd)
for line in output:lines() do
@@ -589,7 +587,7 @@ local function scan_repositories()
if dt.configuration.running_os == "windows" then
find_cmd = "dir /b/s /a:d " .. LUA_DIR .. PS .. "*.git | sort"
end
log.msg(log.debug, _("find command is ") .. find_cmd)
log.msg(log.debug, "find command is " .. find_cmd)
local output = io.popen(find_cmd)
for line in output:lines() do
local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off
@@ -627,7 +625,7 @@ local function install_scripts()
local category = sm.widgets.new_category.text
if string.match(du.join(sm.categories, " "), ds.sanitize_lua(category)) then
log.msg(log.screen, _("category ") .. category .. _(" is already in use. Please specify a different category name."))
log.msg(log.screen, string.format(_("category %s is already in use. Please specify a different category name."), category))
log.msg(log.error, "category " .. category .. " already exists, returning...")
restore_log_level(old_log_level)
return
@@ -658,7 +656,7 @@ local function install_scripts()
local count = scan_scripts(LUA_DIR .. PS .. category)
if count > 0 then
update_combobox_choices(sm.widgets.category_selector, sm.categories, sm.widgets.category_selector.selected)
dt.print(_("scripts successfully installed into category ") .. category)
dt.print(string.format(_("scripts successfully installed into category "), category))
table.insert(sm.installed_repositories, {name = category, directory = LUA_DIR .. PS .. category})
update_script_update_choices()
for i = 1, #sm.widgets.category_selector do
@@ -719,14 +717,14 @@ local function populate_buttons(category, first, last)
button.label = script.name
button.name = "sm_started"
else
button.label = script.name .. _(" started")
button.label = string.format(_("%s started"), script.name)
end
else
if sm.use_color then
button.label = script.name
button.name = "sm_stopped"
else
button.label = script.name .. _(" stopped")
button.label = string.format(_("%s stopped"), script.name)
end
end
button.ellipsize = "middle"
@@ -749,7 +747,7 @@ local function populate_buttons(category, first, last)
if sm.use_color then
this.name = "sm_stopped"
else
this.label = script.name .. _(" stopped")
this.label = string.format(_("%s stopped"), script.name)
end
else
log.msg(log.debug, "activating " .. script.name .. " on " .. script.path .. " for button " .. this.label)
@@ -758,7 +756,7 @@ local function populate_buttons(category, first, last)
if sm.use_color then
this.name = "sm_started"
else
this.label = script.name .. " started"
this.label = string.format(_("%s started"), script.name)
end
end
end
@@ -826,7 +824,7 @@ local function paginate(direction)
else
last = first + sm.page_status.num_buttons - 1
end
sm.widgets.page_status.label = _("Page ") .. cur_page .. _(" of ") .. max_pages
sm.widgets.page_status.label = string.format(_("Page %d of %d"), cur_page, max_pages)
populate_buttons(category, first, last)
restore_log_level(old_log_level)
@@ -1125,7 +1123,7 @@ sm.widgets.install_update = dt.new_widget("box"){
sm.widgets.category_selector = dt.new_widget("combobox"){
label = _("category"),
tooltip = _( "select the script category"),
tooltip = _("select the script category"),
selected = 1,
changed_callback = function(self)
if sm.run then