Add gettext, check for color label
Add translate-ability. Also adds a check that the selected image has an active color label and displays a message if it does not
This commit is contained in:
@@ -46,17 +46,36 @@ In the "Selected Images" module click on "Collect on this Image"
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local dt = require "darktable"
|
local dt = require "darktable"
|
||||||
|
local gettext = dt.gettext
|
||||||
local previous = nil
|
local previous = nil
|
||||||
local all_active = false
|
local all_active = false
|
||||||
|
|
||||||
|
-- Tell gettext where to find the .mo file translating messages for a particular domain
|
||||||
|
gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")
|
||||||
|
|
||||||
|
local function _(msgid)
|
||||||
|
return gettext.dgettext("CollectHelper", msgid)
|
||||||
|
end
|
||||||
|
|
||||||
-- FUNCTION --
|
-- FUNCTION --
|
||||||
local function CheckSingleImage(selection)
|
local function CheckSingleImage(selection)
|
||||||
if #selection ~= 1 then
|
if #selection ~= 1 then
|
||||||
dt.print("Please select a single image")
|
dt.print(_("Please select a single image"))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
local function CheckHasColorLabel(selection)
|
||||||
|
local ret = false
|
||||||
|
for _,image in pairs(selection) do
|
||||||
|
if image.red then ret = true end
|
||||||
|
if image.blue then ret = true end
|
||||||
|
if image.green then ret = true end
|
||||||
|
if image.yellow then ret = true end
|
||||||
|
if image.purple then ret = true end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
local function PreviousCollection()
|
local function PreviousCollection()
|
||||||
if previous ~= nil then
|
if previous ~= nil then
|
||||||
previous = dt.gui.libs.collect.filter(previous)
|
previous = dt.gui.libs.collect.filter(previous)
|
||||||
@@ -87,6 +106,10 @@ local function CollectOnColors(all_rules, all_active)
|
|||||||
if CheckSingleImage(images) then
|
if CheckSingleImage(images) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if not CheckHasColorLabel(images) then
|
||||||
|
dt.print(_('select an image with an active color label'))
|
||||||
|
return
|
||||||
|
end
|
||||||
for _,image in pairs(images) do
|
for _,image in pairs(images) do
|
||||||
local rules = {}
|
local rules = {}
|
||||||
if image.red then
|
if image.red then
|
||||||
@@ -151,48 +174,48 @@ end
|
|||||||
|
|
||||||
-- GUI --
|
-- GUI --
|
||||||
dt.gui.libs.image.register_action(
|
dt.gui.libs.image.register_action(
|
||||||
"collect: previous",
|
_("collect: previous"),
|
||||||
function() PreviousCollection() end,
|
function() PreviousCollection() end,
|
||||||
"Sets the Collect parameters to be the previously active parameters"
|
_("Sets the Collect parameters to be the previously active parameters")
|
||||||
)
|
)
|
||||||
if dt.preferences.read('module_CollectHelper','folder','bool') then
|
if dt.preferences.read('module_CollectHelper','folder','bool') then
|
||||||
dt.gui.libs.image.register_action(
|
dt.gui.libs.image.register_action(
|
||||||
"collect: folder",
|
_("collect: folder"),
|
||||||
function() CollectOnFolder(_ , false) end,
|
function() CollectOnFolder(_ , false) end,
|
||||||
"Sets the Collect parameters to be the selected images's folder"
|
_("Sets the Collect parameters to be the selected images's folder")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if dt.preferences.read('module_CollectHelper','colors','bool') then
|
if dt.preferences.read('module_CollectHelper','colors','bool') then
|
||||||
dt.gui.libs.image.register_action(
|
dt.gui.libs.image.register_action(
|
||||||
"collect: color label(s)",
|
_("collect: color label(s)"),
|
||||||
function() CollectOnColors(_ , false) end,
|
function() CollectOnColors(_ , false) end,
|
||||||
"Sets the Collect parameters to be the selected images's color label(s)"
|
_("Sets the Collect parameters to be the selected images's color label(s)")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if dt.preferences.read('module_CollectHelper','all_and','bool') then
|
if dt.preferences.read('module_CollectHelper','all_and','bool') then
|
||||||
dt.gui.libs.image.register_action(
|
dt.gui.libs.image.register_action(
|
||||||
"collect: all (AND)",
|
_("collect: all (AND)"),
|
||||||
function() CollectOnAll_AND() end,
|
function() CollectOnAll_AND() end,
|
||||||
"Sets the Collect parameters based on all activated CollectHelper options"
|
_("Sets the Collect parameters based on all activated CollectHelper options")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PREFERENCES --
|
-- PREFERENCES --
|
||||||
dt.preferences.register("module_CollectHelper", "all_and", -- name
|
dt.preferences.register("module_CollectHelper", "all_and", -- name
|
||||||
"bool", -- type
|
"bool", -- type
|
||||||
'CollectHelper: All', -- label
|
_('CollectHelper: All'), -- label
|
||||||
'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip
|
_('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip
|
||||||
true -- default
|
true -- default
|
||||||
)
|
)
|
||||||
dt.preferences.register("module_CollectHelper", "colors", -- name
|
dt.preferences.register("module_CollectHelper", "colors", -- name
|
||||||
"bool", -- type
|
"bool", -- type
|
||||||
'CollectHelper: Color Label(s)', -- label
|
_('CollectHelper: Color Label(s)'), -- label
|
||||||
'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip
|
_('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip
|
||||||
true -- default
|
true -- default
|
||||||
)
|
)
|
||||||
dt.preferences.register("module_CollectHelper", "folder", -- name
|
dt.preferences.register("module_CollectHelper", "folder", -- name
|
||||||
"bool", -- type
|
"bool", -- type
|
||||||
'CollectHelper: Folder', -- label
|
_('CollectHelper: Folder'), -- label
|
||||||
'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
|
_('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip
|
||||||
true -- default
|
true -- default
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user