Skip to content

Commit 7ffdf16

Browse files
authored
Make text translatable
1 parent 4b3b1f7 commit 7ffdf16

File tree

1 file changed

+59
-52
lines changed

1 file changed

+59
-52
lines changed

contrib/HDRMerge.lua

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
]]
1818

1919
--[[About this Plugin
20-
This plugin adds the module "HDRMerge" to darktable's lighttable view
20+
This plugin adds the module 'HDRMerge' to darktable's lighttable view
2121
2222
----REQUIRED SOFTWARE----
2323
HDRMerge ver. 4.5 or greater
2424
2525
----USAGE----
2626
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
27-
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
27+
1) Copy this file in to your 'lua/contrib' folder where all other scripts reside.
2828
2) Require this file in your luarc file, as with any other dt plug-in
2929
On the initial startup go to darktable settings > lua options and set your executable paths and other preferences, then restart darktable
3030
@@ -44,13 +44,20 @@ Auto-import Options:
4444
Select a style, whether you want tags to be copied from the original, and any additional tags you desire added when the new image is auto-imported
4545
]]
4646

47-
local dt = require "darktable"
48-
local df = require "lib/dtutils.file"
49-
local dsys = require "lib/dtutils.system"
47+
local dt = require 'darktable'
48+
local df = require 'lib/dtutils.file'
49+
local dsys = require 'lib/dtutils.system'
5050
local mod = 'module_HDRMerge'
5151
local os_path_seperator = '/'
5252
if dt.configuration.running_os == 'windows' then os_path_seperator = '\\' end
5353

54+
-- Tell gettext where to find the .mo file translating messages for a particular domain
55+
local gettext = dt.gettext
56+
gettext.bindtextdomain('HDRMerge',dt.configuration.config_dir..'/lua/locale/')
57+
local function _(msgid)
58+
return gettext.dgettext('HDRMerge', msgid)
59+
end
60+
5461
local temp
5562
local HDRM = { --HDRMerge Program Table
5663
name = 'HDRMerge',
@@ -89,9 +96,9 @@ local GUI = { --GUI Elements Table
8996

9097
--Detect User Styles--
9198
local styles = dt.styles
92-
local styles_count = 1 -- "none" = 1
99+
local styles_count = 1 -- 'none' = 1
93100
for _,i in pairs(dt.styles) do
94-
if type(i) == "userdata" then styles_count = styles_count + 1 end
101+
if type(i) == 'userdata' then styles_count = styles_count + 1 end
95102
end
96103

97104
local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive)
@@ -114,10 +121,10 @@ local function GetFileName(full_path) --Parses a full path (path/filename_identi
114121
EX:
115122
path_1, file_1, id_1, ext_1 = GetFileName(full_path_1)
116123
]]
117-
local path = string.match(full_path, ".*[\\/]")
118-
local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" )
119-
local identifier = string.match(filename, "%d*$")
120-
local extension = string.match(full_path, "%.%w*")
124+
local path = string.match(full_path, '.*[\\/]')
125+
local filename = string.gsub(string.match(full_path, '[%w-_]*%.') , '%.' , '' )
126+
local identifier = string.match(filename, '%d*$')
127+
local extension = string.match(full_path, '%.%w*')
121128
return path, filename, identifier, extension
122129
end
123130

@@ -147,7 +154,7 @@ local function PreCall(prog_tbl) --looks to see if this is the first call, if so
147154
end
148155
if not dt.preferences.read(mod, 'bin_exists', 'bool') then
149156
GUI.stack.active = 2
150-
dt.print('please update you binary locatoin')
157+
dt.print(_('please update you binary locatoin'))
151158
end
152159
end
153160

@@ -166,9 +173,9 @@ local function ExeUpdate(prog_tbl)
166173
end
167174
if dt.preferences.read(mod, 'bin_exists', 'bool') then
168175
GUI.stack.active = 1
169-
dt.print('update successful')
176+
dt.print(_('update successful'))
170177
else
171-
dt.print('update unsuccessful, please try again')
178+
dt.print(_('update unsuccessful, please try again'))
172179
end
173180
end
174181

@@ -182,13 +189,13 @@ end
182189
local function main()
183190
PreCall({HDRM}) --check if furst run then check if install OK
184191
if HDRM.install_error then
185-
dt.print_error('HDRMerge install issue')
186-
dt.print('HDRMerge install issue, please ensure the binary path is proper')
192+
dt.print_error(_('HDRMerge install issue'))
193+
dt.print(_('HDRMerge install issue, please ensure the binary path is proper'))
187194
return
188195
end
189196
images = dt.gui.selection() --get selected images
190197
if #images < 2 then --ensure enough images selected
191-
dt.print('not enough images selected, select at least 2 images to merge')
198+
dt.print(_('not enough images selected, select at least 2 images to merge'))
192199
return
193200
end
194201

@@ -203,7 +210,7 @@ local function main()
203210
local source_raw = {}
204211
for _,image in pairs(images) do --loop to concat the images string, also track the image indexes for use in creating the final image name (eg; IMG_1034-1037.dng)
205212
local curr_image = image.path..os_path_seperator..image.filename
206-
HDRM.images_string = HDRM.images_string..df.sanitize_filename(curr_image).." "
213+
HDRM.images_string = HDRM.images_string..df.sanitize_filename(curr_image)..' '
207214
out_path = image.path
208215
_, source_name, source_id = GetFileName(image.filename)
209216
source_id = tonumber(source_id)
@@ -249,23 +256,23 @@ local function main()
249256
dt.tags.attach(tag, imported)
250257
end
251258
end
252-
dt.print('HDRMerge completed successfully')
259+
dt.print(_('HDRMerge completed successfully'))
253260
else
254-
dt.print_error('HDRMerge failed')
255-
dt.print('HDRMerge failed')
261+
dt.print_error(_('HDRMerge failed'))
262+
dt.print(_('HDRMerge failed'))
256263
end
257264

258265
end
259266

260267
-- GUI Elements --
261268
local lbl_hdr = dt.new_widget('section_label'){
262-
label = 'HDRMerge options'
269+
label = _('HDRMerge options')
263270
}
264271
temp = dt.preferences.read(mod, 'active_bps_ind', 'integer')
265272
if not InRange(temp, 1, 3) then temp = 3 end
266273
GUI.HDR.bps = dt.new_widget('combobox'){
267-
label = 'bits per sample',
268-
tooltip ='number of bits per sample in the output image',
274+
label = _('bits per sample'),
275+
tooltip =_('number of bits per sample in the output image'),
269276
selected = temp,
270277
'16','24','32',
271278
changed_callback = function(self)
@@ -281,10 +288,10 @@ GUI.HDR.bps = dt.new_widget('combobox'){
281288
temp = dt.preferences.read(mod, 'active_size_ind', 'integer')
282289
if not InRange(temp, 1, 3) then temp = 2 end
283290
GUI.HDR.size = dt.new_widget('combobox'){
284-
label = 'embedded preview size',
285-
tooltip ='size of the embedded preview in output image',
291+
label = _('embedded preview size'),
292+
tooltip =_('size of the embedded preview in output image'),
286293
selected = temp,
287-
'none','half','full',
294+
_('none'),_('half'),_('full'),
288295
changed_callback = function(self)
289296
dt.preferences.write(mod, 'active_size', 'string', self.value)
290297
dt.preferences.write(mod, 'active_size_ind', 'integer', self.selected)
@@ -296,9 +303,9 @@ GUI.HDR.size = dt.new_widget('combobox'){
296303
end
297304
}
298305
GUI.HDR.batch = dt.new_widget('check_button'){
299-
label = 'batch mode',
306+
label = _('batch mode'),
300307
value = dt.preferences.read(mod, 'active_batch', 'bool'),
301-
tooltip = 'enable batch mode operation \nNOTE: resultant files will NOT be auto-imported',
308+
tooltip = _('enable batch mode operation \nNOTE: resultant files will NOT be auto-imported'),
302309
clicked_callback = function(self)
303310
dt.preferences.write(mod, 'active_batch', 'bool', self.value)
304311
GUI.HDR.gap.sensitive = self.value
@@ -308,8 +315,8 @@ GUI.HDR.batch = dt.new_widget('check_button'){
308315
temp = dt.preferences.read(mod, 'active_gap', 'integer')
309316
if not InRange(temp, 1, 3600) then temp = 3 end
310317
GUI.HDR.gap = dt.new_widget('slider'){
311-
label = 'batch gap [sec.]',
312-
tooltip = 'gap, in seconds, between batch mode groups',
318+
label = _('batch gap [sec.]'),
319+
tooltip = _('gap, in seconds, between batch mode groups'),
313320
soft_min = 1,
314321
soft_max = 30,
315322
hard_min = 1,
@@ -323,13 +330,13 @@ GUI.HDR.gap = dt.new_widget('slider'){
323330
end
324331
}
325332
local lbl_import = dt.new_widget('section_label'){
326-
label = 'import options'
333+
label = _('import options')
327334
}
328335
GUI.Target.style = dt.new_widget('combobox'){
329-
label = 'apply style on import',
330-
tooltip = "Apply selected style on auto-import to newly created image",
336+
label = _('apply style on import'),
337+
tooltip = _('Apply selected style on auto-import to newly created image'),
331338
selected = 1,
332-
"none",
339+
_('none'),
333340
changed_callback = function(self)
334341
dt.preferences.write(mod, 'active_style', 'string', self.value)
335342
dt.preferences.write(mod, 'active_style_ind', 'integer', self.selected)
@@ -347,33 +354,33 @@ temp = dt.preferences.read(mod, 'active_style_ind', 'integer')
347354
if not InRange(temp, 1, styles_count) then temp = 1 end
348355
GUI.Target.style.selected = temp
349356
GUI.Target.copy_tags = dt.new_widget('check_button'){
350-
label = 'copy tags',
357+
label = _('copy tags'),
351358
value = dt.preferences.read(mod, 'active_copy_tags', 'bool'),
352-
tooltip = 'copy tags from first source image',
359+
tooltip = _('copy tags from first source image'),
353360
clicked_callback = function(self) dt.preferences.write(mod, 'active_copy_tags', 'bool', self.value) end,
354361
reset_callback = function(self) self.value = true end
355362
}
356363
temp = dt.preferences.read(mod, 'active_add_tags', 'string')
357364
if temp == '' then temp = nil end
358-
GUI.Target.add_tags = dt.new_widget("entry"){
359-
tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed",
365+
GUI.Target.add_tags = dt.new_widget('entry'){
366+
tooltip = _('Additional tags to be added on import. Seperate with commas, all spaces will be removed'),
360367
text = temp,
361-
placeholder = "Enter tags, seperated by commas",
368+
placeholder = _('Enter tags, seperated by commas'),
362369
editable = true
363370
}
364-
GUI.run = dt.new_widget("button"){
365-
label = 'merge',
366-
tooltip ='run HDRMerge with the above specified settings',
371+
GUI.run = dt.new_widget('button'){
372+
label = _('merge'),
373+
tooltip =_('run HDRMerge with the above specified settings'),
367374
clicked_callback = function() main() end
368375
}
369376
GUI.exes.HDRMerge = dt.new_widget('file_chooser_button'){
370-
title = "Select HDRmerge executable",
377+
title = _('Select HDRmerge executable'),
371378
value = df.get_executable_path_preference(HDRM.name),
372379
is_directory = false
373380
}
374381
GUI.exes.update = dt.new_widget('button'){
375-
label = 'update',
376-
tooltip ='update the binary path with current value',
382+
label = _('update'),
383+
tooltip =_('update the binary path with current value'),
377384
clicked_callback = function() ExeUpdate({HDRM}) end
378385
}
379386
GUI.options = dt.new_widget('box'){
@@ -399,19 +406,19 @@ GUI.stack = dt.new_widget('stack'){
399406
exes_box
400407
}
401408
if dt.preferences.read(mod, 'bin_exists', 'bool') then
402-
GUI.stack.active = 1
409+
GUI.stack.active = 1
403410
else
404411
GUI.stack.active = 2
405412
end
406413

407414
dt.register_lib( -- register HDRMerge module
408-
"HDRMerge_Lib", -- Module name
409-
"HDRMerge", -- name
415+
'HDRMerge_Lib', -- Module name
416+
_('HDRMerge'), -- name
410417
true, -- expandable
411418
true, -- resetable
412-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
413-
dt.new_widget("box"){
414-
orientation = "vertical",
419+
{[dt.gui.views.lighttable] = {'DT_UI_CONTAINER_PANEL_RIGHT_CENTER', 99}}, -- containers
420+
dt.new_widget('box'){
421+
orientation = 'vertical',
415422
GUI.stack
416423
}
417424
)

0 commit comments

Comments
 (0)