Skip to content

Commit 9e0490d

Browse files
authored
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
1 parent b682284 commit 9e0490d

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

contrib/CollectHelper.lua

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,36 @@ In the "Selected Images" module click on "Collect on this Image"
4646
]]
4747

4848
local dt = require "darktable"
49+
local gettext = dt.gettext
4950
local previous = nil
5051
local all_active = false
5152

53+
-- Tell gettext where to find the .mo file translating messages for a particular domain
54+
gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")
55+
56+
local function _(msgid)
57+
return gettext.dgettext("CollectHelper", msgid)
58+
end
59+
5260
-- FUNCTION --
5361
local function CheckSingleImage(selection)
5462
if #selection ~= 1 then
55-
dt.print("Please select a single image")
63+
dt.print(_("Please select a single image"))
5664
return true
5765
end
5866
return false
5967
end
68+
local function CheckHasColorLabel(selection)
69+
local ret = false
70+
for _,image in pairs(selection) do
71+
if image.red then ret = true end
72+
if image.blue then ret = true end
73+
if image.green then ret = true end
74+
if image.yellow then ret = true end
75+
if image.purple then ret = true end
76+
end
77+
return ret
78+
end
6079
local function PreviousCollection()
6180
if previous ~= nil then
6281
previous = dt.gui.libs.collect.filter(previous)
@@ -87,6 +106,10 @@ local function CollectOnColors(all_rules, all_active)
87106
if CheckSingleImage(images) then
88107
return
89108
end
109+
if not CheckHasColorLabel(images) then
110+
dt.print(_('select an image with an active color label'))
111+
return
112+
end
90113
for _,image in pairs(images) do
91114
local rules = {}
92115
if image.red then
@@ -151,48 +174,48 @@ end
151174

152175
-- GUI --
153176
dt.gui.libs.image.register_action(
154-
"collect: previous",
177+
_("collect: previous"),
155178
function() PreviousCollection() end,
156-
"Sets the Collect parameters to be the previously active parameters"
179+
_("Sets the Collect parameters to be the previously active parameters")
157180
)
158181
if dt.preferences.read('module_CollectHelper','folder','bool') then
159182
dt.gui.libs.image.register_action(
160-
"collect: folder",
183+
_("collect: folder"),
161184
function() CollectOnFolder(_ , false) end,
162-
"Sets the Collect parameters to be the selected images's folder"
185+
_("Sets the Collect parameters to be the selected images's folder")
163186
)
164187
end
165188
if dt.preferences.read('module_CollectHelper','colors','bool') then
166189
dt.gui.libs.image.register_action(
167-
"collect: color label(s)",
190+
_("collect: color label(s)"),
168191
function() CollectOnColors(_ , false) end,
169-
"Sets the Collect parameters to be the selected images's color label(s)"
192+
_("Sets the Collect parameters to be the selected images's color label(s)")
170193
)
171194
end
172195
if dt.preferences.read('module_CollectHelper','all_and','bool') then
173196
dt.gui.libs.image.register_action(
174-
"collect: all (AND)",
197+
_("collect: all (AND)"),
175198
function() CollectOnAll_AND() end,
176-
"Sets the Collect parameters based on all activated CollectHelper options"
199+
_("Sets the Collect parameters based on all activated CollectHelper options")
177200
)
178201
end
179202

180203
-- PREFERENCES --
181204
dt.preferences.register("module_CollectHelper", "all_and", -- name
182205
"bool", -- type
183-
'CollectHelper: All', -- label
184-
'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip
206+
_('CollectHelper: All'), -- label
207+
_('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip
185208
true -- default
186209
)
187210
dt.preferences.register("module_CollectHelper", "colors", -- name
188211
"bool", -- type
189-
'CollectHelper: Color Label(s)', -- label
190-
'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip
212+
_('CollectHelper: Color Label(s)'), -- label
213+
_('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip
191214
true -- default
192215
)
193216
dt.preferences.register("module_CollectHelper", "folder", -- name
194217
"bool", -- type
195-
'CollectHelper: Folder', -- label
196-
'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
218+
_('CollectHelper: Folder'), -- label
219+
_('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip
197220
true -- default
198221
)

0 commit comments

Comments
 (0)