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:
@@ -45,9 +45,7 @@ script_data.show = nil -- only required for libs since the destroy_method only h
|
||||
|
||||
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
|
||||
|
||||
local gettext = dt.gettext
|
||||
|
||||
gettext.bindtextdomain("executable_manager",dt.configuration.config_dir.."/lua/locale/")
|
||||
local gettext = dt.gettext.gettext
|
||||
|
||||
local exec_man = {} -- our own namespace
|
||||
exec_man.module_installed = false
|
||||
@@ -58,7 +56,7 @@ exec_man.event_registered = false
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
local function _(msg)
|
||||
return gettext.dgettext("executable_manager", msg)
|
||||
return gettext(msg)
|
||||
end
|
||||
|
||||
local function grep(file, pattern)
|
||||
@@ -167,7 +165,7 @@ for i,exec in ipairs(exec_table) do
|
||||
editable = false
|
||||
}
|
||||
executable_path_widgets[exec] = dt.new_widget("file_chooser_button"){
|
||||
title = _("select ") .. exec .. _(" executable"),
|
||||
title = _(string.format("select %s executable", exec)),
|
||||
value = df.get_executable_path_preference(exec),
|
||||
is_directory = false,
|
||||
changed_callback = function(self)
|
||||
@@ -210,7 +208,7 @@ for i,exec in ipairs(exec_table) do
|
||||
dt.new_widget("section_label"){label = _("reset")},
|
||||
dt.new_widget("button"){
|
||||
label = _("clear"),
|
||||
tooltip = _("Clear path for ") .. exec,
|
||||
tooltip = _(string.format("Clear path for %s", exec)),
|
||||
clicked_callback = function()
|
||||
df.set_executable_path_preference(exec, "")
|
||||
executable_path_widgets[exec].value = ""
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
--[[
|
||||
gen_18n_mo.lua - generate .mo files from .po files and put them in the correct place
|
||||
|
||||
Copyright (C) 2016,2018 Bill Ferguson <wpferguson@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
]]
|
||||
--[[
|
||||
gen_i18n_mo - generate translation files from the source and place them in the appropriate locale directory
|
||||
|
||||
gen_i18n_mo finds all the .po files scattered throughout the script tree, compiles them into
|
||||
.mo files and places them in the correct locale directory for use by the gettext tools.
|
||||
|
||||
]]
|
||||
|
||||
local dt = require "darktable"
|
||||
local du = require "lib/dtutils"
|
||||
local df = require "lib/dtutils.file"
|
||||
local log = require "lib/dtutils.log"
|
||||
local dtsys = require "lib/dtutils.system"
|
||||
|
||||
du.check_min_api_version("5.0.0", "gen_I18n_mo")
|
||||
|
||||
local function destroy()
|
||||
-- nothing to destroy
|
||||
end
|
||||
|
||||
-- figure out the path separator
|
||||
|
||||
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
|
||||
|
||||
local LUA_DIR = dt.configuration.config_dir .. PS .. "lua" .. PS
|
||||
local LOCALE_DIR = dt.configuration.config_dir .. PS .. "lua" .. PS .. "locale" .. PS
|
||||
|
||||
-- check if we have msgfmt
|
||||
|
||||
local msgfmt_executable = df.check_if_bin_exists("msgfmt")
|
||||
|
||||
if msgfmt_executable then
|
||||
|
||||
-- find the .po files
|
||||
|
||||
local find_cmd = "find -L " .. LUA_DIR .. " -name \\*.po -print"
|
||||
if dt.configuration.running_os == "windows" then
|
||||
find_cmd = "dir /b/s " .. LUA_DIR .. "\\*.po"
|
||||
end
|
||||
|
||||
local output = io.popen(find_cmd)
|
||||
|
||||
-- for each .po file....
|
||||
|
||||
for line in output:lines() do
|
||||
local fname = df.get_filename(line)
|
||||
|
||||
-- get the language used... this depends on the file being named using
|
||||
-- the convention /..../lang/LC_MESSAGES/file.po where lang is de_DE, fr_FR, etc.
|
||||
|
||||
local path_parts = du.split(line, PS)
|
||||
local lang = path_parts[#path_parts - 2]
|
||||
|
||||
-- ensure there is a destination directory for them
|
||||
|
||||
local mkdir_cmd = "mkdir -p "
|
||||
if dt.configuration.running_os == "windows" then
|
||||
mkdir_cmd = "mkdir "
|
||||
end
|
||||
|
||||
if not df.check_if_file_exists(LOCALE_DIR .. lang .. PS .. "LC_MESSAGES") then
|
||||
log.msg(log.info, "Creating locale", lang)
|
||||
os.execute(mkdir_cmd .. LOCALE_DIR .. lang .. PS .. "LC_MESSAGES")
|
||||
end
|
||||
|
||||
-- generate the mo file
|
||||
|
||||
fname = string.gsub(fname, ".po$", ".mo")
|
||||
log.msg(log.info, "Compiling translation to", fname)
|
||||
local result = os.execute(msgfmt_executable .. " -o " .. LOCALE_DIR .. lang .. PS .. "LC_MESSAGES" .. PS .. fname .. " " .. line)
|
||||
end
|
||||
else
|
||||
log.msg(log.screen, "ERROR: msgfmt executable not found. Please install or specifiy location in preferences.")
|
||||
end
|
||||
dt.preferences.register("executable_paths", "msgfmt", -- name
|
||||
"file", -- type
|
||||
'gen_i18n_mo: msgfmt location', -- label
|
||||
'Install location of msgfmt. Requires restart to take effect.', -- tooltip
|
||||
"msgfmt", -- default
|
||||
dt.new_widget("file_chooser_button"){
|
||||
title = "Select msgfmt[.exe] file",
|
||||
value = "",
|
||||
is_directory = false,
|
||||
}
|
||||
)
|
||||
|
||||
local script_data = {}
|
||||
script_data.destroy = destroy
|
||||
|
||||
return script_data
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user