From 37dba718a28b0af9feb27779ec97fc4904452884 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 20 Jan 2024 15:25:16 -0500 Subject: [PATCH] updated official scripts to use darktable translation facilities --- official/copy_paste_metadata.lua | 11 ++++------- official/delete_long_tags.lua | 2 +- official/delete_unused_tags.lua | 2 +- official/enfuse.lua | 21 +++++++++------------ official/generate_image_txt.lua | 16 +++++++++++----- official/import_filter_manager.lua | 12 +++++++++--- official/import_filters.lua | 2 +- official/save_selection.lua | 12 +++++++++--- official/selection_to_pdf.lua | 26 ++++++++++++++++---------- 9 files changed, 61 insertions(+), 43 deletions(-) diff --git a/official/copy_paste_metadata.lua b/official/copy_paste_metadata.lua index ffd69c8..3afb953 100644 --- a/official/copy_paste_metadata.lua +++ b/official/copy_paste_metadata.lua @@ -27,7 +27,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" -local gettext = dt.gettext +local gettext = dt.gettext.gettext du.check_min_api_version("7.0.0", "copy_paste_metadata") @@ -58,11 +58,8 @@ local publisher = "" local rights = "" local tags = {} --- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("copy_paste_metadata",dt.configuration.config_dir.."/lua/locale/") - local function _(msgid) - return gettext.dgettext("copy_paste_metadata", msgid) + return gettext(msgid) end local function copy(image) @@ -147,13 +144,13 @@ dt.gui.libs.image.register_action( dt.register_event( "capmd1", "shortcut", function(event, shortcut) copy(dt.gui.action_images[1]) end, - "copy metadata" + _("copy metadata") ) dt.register_event( "capmd2", "shortcut", function(event, shortcut) paste(dt.gui.action_images) end, - "paste metadata" + _("paste metadata") ) script_data.destroy = destroy diff --git a/official/delete_long_tags.lua b/official/delete_long_tags.lua index 31ae799..2c5d0e6 100644 --- a/official/delete_long_tags.lua +++ b/official/delete_long_tags.lua @@ -59,7 +59,7 @@ local long_tags = {} for _,t in ipairs(dt.tags) do local len = #t.name if len > max_length then - print("deleting tag `"..t.name.."' (length: "..len..")") + dt.print_log("deleting tag `"..t.name.."' (length: "..len..")") table.insert(long_tags, t.name) end end diff --git a/official/delete_unused_tags.lua b/official/delete_unused_tags.lua index 0dfab01..e169068 100644 --- a/official/delete_unused_tags.lua +++ b/official/delete_unused_tags.lua @@ -56,7 +56,7 @@ for _, t in ipairs(dt.tags) do end for _,name in pairs(unused_tags) do - print("deleting tag `" .. name .. "'") + dt.print_log("deleting tag `" .. name .. "'") tag = dt.tags.find(name) tag:delete() end diff --git a/official/enfuse.lua b/official/enfuse.lua index 35327cf..fb94229 100644 --- a/official/enfuse.lua +++ b/official/enfuse.lua @@ -39,7 +39,7 @@ local dtsys = require "lib/dtutils.system" local PS = dt.configuration.running_os == "windows" and "\\" or "/" -local gettext = dt.gettext +local gettext = dt.gettext.gettext du.check_min_api_version("7.0.0", "enfuse") @@ -52,16 +52,13 @@ script_data.destroy_method = nil -- set to hide for libs since we can't destroy script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again script_data.show = nil -- only required for libs since the destroy_method only hides them --- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("enfuse",dt.configuration.config_dir..PS .. "lua" .. PS .. "locale" .. PS) - local enf = {} enf.event_registered = false enf.module_installed = false enf.lib_widgets = {} local function _(msgid) - return gettext.dgettext("enfuse", msgid) + return gettext(msgid) end local function install_module() @@ -132,7 +129,7 @@ if enfuse_installed then exposure_mu = dt.new_widget("slider") { label = "exposure mu", - tooltip = "center also known as MEAN of Gaussian weighting function (0 <= MEAN <= 1); default: 0.5", + tooltip = _("center also known as MEAN of Gaussian weighting function (0 <= MEAN <= 1); default: 0.5"), hard_min = 0, hard_max = 1, value = dt.preferences.read("enfuse", "exposure_mu", "float") @@ -141,7 +138,7 @@ if enfuse_installed then exposure_mu = dt.new_widget("slider") { label = "exposure optimum", - tooltip = "optimum exposure value, usually the maximum of the weighting function (0 <= OPTIMUM <=1); default 0.5", + tooltip = _("optimum exposure value, usually the maximum of the weighting function (0 <= OPTIMUM <=1); default 0.5"), hard_min = 0, hard_max = 1, value = dt.preferences.read("enfuse", "exposure_optimum", "float") @@ -151,7 +148,7 @@ if enfuse_installed then local depth = dt.new_widget("combobox") { label = "depth", - tooltip = "the number of bits per channel of the output image", + tooltip = _("the number of bits per channel of the output image"), value = dt.preferences.read("enfuse", "depth", "integer"), changed_callback = function(w) dt.preferences.write("enfuse", "depth", "integer", w.selected) end, "8", "16", "32" @@ -160,14 +157,14 @@ if enfuse_installed then local blend_colorspace = dt.new_widget("combobox") { label = "blend colorspace", - tooltip = "Force blending in selected colorspace", + tooltip = _("force blending in selected colorspace"), changed_callback = function(w) dt.preferences.write("enfuse", "blend_colorspace", "string", w.selected) end, "", "identity", "ciecam" } local enfuse_button = dt.new_widget("button") { - label = enfuse_installed and "run enfuse" or "enfuse not installed", + label = enfuse_installed and _("run enfuse") or _("enfuse not installed"), clicked_callback = function () -- remember exposure_mu -- TODO: find a way to save it whenever the value changes @@ -185,7 +182,7 @@ if enfuse_installed then end local f = io.open(response_file, "w") if not f then - dt.print(string.format(_("Error writing to `%s`"), response_file)) + dt.print(string.format(_("Error writing to '%s'"), response_file)) os.remove(response_file) return end @@ -251,7 +248,7 @@ if enfuse_installed then ..blend_colorspace_option .." -o \""..output_image.."\" \"@"..response_file.."\"" if dtsys.external_command( command) > 0 then - dt.print(_("Enfuse failed, see terminal output for details")) + dt.print(_("enfuse failed, see terminal output for details")) os.remove(response_file) return end diff --git a/official/generate_image_txt.lua b/official/generate_image_txt.lua index 73b5063..3eeafbe 100644 --- a/official/generate_image_txt.lua +++ b/official/generate_image_txt.lua @@ -38,6 +38,12 @@ local dt = require "darktable" local du = require "lib/dtutils" require "darktable.debug" +local gettext = dt.gettext.gettext + +local function _(msg) + return gettext(msg) +end + du.check_min_api_version("7.0.0", "generate_image_txt") -- return data structure for script_manager @@ -52,21 +58,21 @@ script_data.show = nil -- only required for libs since the destroy_method only h dt.preferences.register("generate_image_txt", "enabled", "bool", - "create txt sidecars to display with images", - "the txt files created get shown when the lighttable is zoomed in to one image. also enable the txt overlay setting in the gui tab", + _("create txt sidecars to display with images"), + _("the txt files created get shown when the lighttable is zoomed in to one image. also enable the txt overlay setting in the gui tab"), false) dt.preferences.register("generate_image_txt", "command", "string", - "command to generate the txt sidecar", - "the output of this command gets written to the txt file. use $(FILE_NAME) for the image file", + _("command to generate the txt sidecar"), + _("the output of this command gets written to the txt file. use $(FILE_NAME) for the image file"), "exiv2 $(FILE_NAME)") local check_command = function(command) if not command:find("$(FILE_NAME)", 1, true) then - dt.print("the command for txt sidecars looks bad. better check the preferences") + dt.print(_("the command for txt sidecars looks bad. better check the preferences")) end end diff --git a/official/import_filter_manager.lua b/official/import_filter_manager.lua index c648c1a..7a81f2c 100644 --- a/official/import_filter_manager.lua +++ b/official/import_filter_manager.lua @@ -32,20 +32,26 @@ USAGE local dt = require "darktable" +local gettext = dt.gettext.gettext + +local function _(msg) + return gettext(msg) +end + local import_filter_list = {} local n_import_filters = 1 -- allow changing the filter from the preferences dt.preferences.register("import_filter_manager", "active_filter", "string", - "import filter", "the name of the filter used for importing images", "") + _("import filter"), _("the name of the filter used for importing images"), "") -- the dropdown to select the active filter from the import dialog local filter_dropdown = dt.new_widget("combobox") { - label = "import filter", + label = _("import filter"), editable = false, - tooltip = "import filters are applied after completion of the import dialog", + tooltip = _("import filters are applied after completion of the import dialog"), changed_callback = function(widget) dt.preferences.write("import_filter_manager", "active_filter", "string", widget.value) diff --git a/official/import_filters.lua b/official/import_filters.lua index 584a271..807dec6 100644 --- a/official/import_filters.lua +++ b/official/import_filters.lua @@ -34,7 +34,7 @@ local dt = require "darktable" -- ignore jpeg dt.register_import_filter("ignore jpegs", function(event, images) - dt.print_error("ignoring all jpegs") + dt.print_log("ignoring all jpegs") for i, img in ipairs(images) do local extension = img:match("[^.]*$"):upper() if (extension == "JPG") or (extension == "JPEG") then diff --git a/official/save_selection.lua b/official/save_selection.lua index b06f933..22841a9 100644 --- a/official/save_selection.lua +++ b/official/save_selection.lua @@ -38,6 +38,12 @@ local du = require "lib/dtutils" du.check_min_api_version("7.0.0", "save_selection") +local gettext = dt.gettext.gettext + +local function _(msg) + return gettext(msg) +end + -- return data structure for script_manager local script_data = {} @@ -61,16 +67,16 @@ for i = 1, buffer_count do local saved_selection dt.register_event("save_selection save " .. i, "shortcut", function() saved_selection = dt.gui.selection() - end, "save to buffer " .. i) + end, string.format(_("save to buffer %d"), i)) dt.register_event("save_selection restore " .. i, "shortcut", function() dt.gui.selection(saved_selection) - end, "restore from buffer " .. i) + end, string.format(_("restore from buffer %d"), i)) end local bounce_buffer = {} dt.register_event("save_selection switch", "shortcut", function() bounce_buffer = dt.gui.selection(bounce_buffer) -end, "switch selection with temporary buffer") +end, _("switch selection with temporary buffer")) script_data.destroy = destroy diff --git a/official/selection_to_pdf.lua b/official/selection_to_pdf.lua index 638ae24..9e1d7b4 100644 --- a/official/selection_to_pdf.lua +++ b/official/selection_to_pdf.lua @@ -38,6 +38,12 @@ local du = require "lib/dtutils" du.check_min_api_version("7.0.0", "selection_to_pdf") +local gettext = dt.gettext.gettext + +local function _(msg) + return gettext(msg) +end + -- return data structure for script_manager local script_data = {} @@ -49,16 +55,16 @@ script_data.show = nil -- only required for libs since the destroy_method only h dt.preferences.register ("selection_to_pdf","Open with","string", - "a pdf viewer", - "Can be an absolute pathname or the tool may be in the PATH", + _("a pdf viewer"), + _("Can be an absolute pathname or the tool may be in the PATH"), "xdg-open") local title_widget = dt.new_widget("entry") { - placeholder="Title" + placeholder = _("Title") } local no_of_thumbs_widget = dt.new_widget("slider") { - label = "Thumbs per Line", + label = _("Thumbs per Line"), soft_min = 1, -- The soft minimum value for the slider, the slider can't go beyond this point soft_max = 10, -- The soft maximum value for the slider, the slider can't go beyond this point hard_min = 1, -- The hard minimum value for the slider, the user can't manually enter a value beyond this point @@ -66,10 +72,10 @@ local no_of_thumbs_widget = dt.new_widget("slider") value = 4 -- The current value of the slider } local widget = dt.new_widget("box") { - orientation=horizontal, - dt.new_widget("label"){label = "Title:"}, + orientation = horizontal, + dt.new_widget("label"){label = _("Title:")}, title_widget, - dt.new_widget("label"){label = "Thumbnails per row:"}, + dt.new_widget("label"){label = _("Thumbnails per row:")}, no_of_thumbs_widget } @@ -116,7 +122,7 @@ local function destroy() dt.print_log("done destroying") end -dt.register_storage("export_pdf","Export thumbnails to pdf", +dt.register_storage(_("export_pdf"),_("Export thumbnails to pdf"), nil, function(storage,image_table) local my_title = title_widget.text @@ -163,7 +169,7 @@ dt.register_storage("export_pdf","Export thumbnails to pdf", local command = "pdflatex -halt-on-error -output-directory "..dir.." "..locfile local result = dt.control.execute(command) if result ~= 0 then - dt.print("Problem running pdflatex") -- this one is probably usefull to the user + dt.print(_("Problem running pdflatex")) -- this one is probably usefull to the user error("Problem running "..command) end @@ -173,7 +179,7 @@ dt.register_storage("export_pdf","Export thumbnails to pdf", command = command.." "..pdffile local result = dt.control.execute(command) if result ~= 0 then - dt.print("Problem running pdf viewer") -- this one is probably usefull to the user + dt.print(_("Problem running pdf viewer")) -- this one is probably usefull to the user error("Problem running "..command) end