Merge pull request #455 from wpferguson/prep_translation

Prepare translatable strings, step 1
This commit is contained in:
wpferguson
2024-05-15 15:18:11 -04:00
committed by GitHub
64 changed files with 640 additions and 643 deletions

View File

@@ -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
@@ -57,8 +55,10 @@ exec_man.event_registered = false
-- F U N C T I O N S
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
gettext.bindtextdomain("executable_manager", dt.configuration.config_dir .."/lua/locale/")
local function _(msg)
return gettext.dgettext("executable_manager", msg)
return gettext(msg)
end
local function grep(file, pattern)
@@ -142,7 +142,7 @@ local matches = grep(DARKTABLERC, "executable_paths")
-- check if we have something to manage and exit if not
if #matches == 0 then
dt.print(_("No executable paths found, exiting..."))
dt.print(_("no executable paths found, exiting..."))
return
end
@@ -167,7 +167,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 +210,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 = ""

View File

@@ -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

View File

@@ -56,14 +56,14 @@ local dtsys = require "lib/dtutils.system"
local log = require "lib/dtutils.log"
local debug = require "darktable.debug"
local gettext = dt.gettext
-- set up translation
local gettext = dt.gettext.gettext
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("script_manager",dt.configuration.config_dir.."/lua/locale/")
gettext.bindtextdomain("script_manager", dt.configuration.config_dir .."/lua/locale/")
local function _(msgid)
return gettext.dgettext("script_manager", msgid)
return gettext(msgid)
end
-- api check
@@ -369,7 +369,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 +392,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 +404,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 +443,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
@@ -545,7 +545,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
@@ -575,7 +575,7 @@ local function update_scripts()
local git = sm.executables.git
if not git then
dt.print(_("ERROR: git not found. Install or specify the location of the git executable."))
dt.print(_("ERROR: git not found, install or specify the location of the git executable."))
return
end
@@ -621,7 +621,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
@@ -659,7 +659,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
@@ -670,7 +670,7 @@ local function install_scripts()
local git = sm.executables.git
if not git then
dt.print(_("ERROR: git not found. Install or specify the location of the git executable."))
dt.print(_("ERROR: git not found, install or specify the location of the git executable."))
restore_log_level(old_log_level)
return
end
@@ -690,7 +690,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
@@ -706,7 +706,7 @@ local function install_scripts()
sm.widgets.new_category.text = ""
sm.widgets.main_menu.selected = 3
else
dt.print(_("No scripts found to install"))
dt.print(_("no scripts found to install"))
log.msg(log.error, "scan_scripts returned " .. count .. " scripts found. Not adding to category_selector")
end
else
@@ -751,14 +751,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"
@@ -781,7 +781,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)
@@ -790,7 +790,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
@@ -858,7 +858,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)
@@ -1121,7 +1121,7 @@ sm.widgets.add_scripts = dt.new_widget("box"){
}
sm.widgets.allow_disable = dt.new_widget("check_button"){
label = _('Enable "Disable Scripts" button'),
label = _('enable "disable scripts" button'),
value = false,
clicked_callback = function(this)
if this.value == true then
@@ -1131,7 +1131,7 @@ sm.widgets.allow_disable = dt.new_widget("check_button"){
}
sm.widgets.disable_scripts = dt.new_widget("button"){
label = _("Disable Scripts"),
label = _("disable scripts"),
sensitive = false,
clicked_callback = function(this)
local LUARC = dt.configuration.config_dir .. PS .. "luarc"
@@ -1157,7 +1157,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
@@ -1177,7 +1177,7 @@ end
local page_back = "<"
local page_forward = ">"
sm.widgets.page_status = dt.new_widget("label"){label = _("Page:")}
sm.widgets.page_status = dt.new_widget("label"){label = _("page:")}
sm.widgets.page_back = dt.new_widget("button"){
label = page_back,
clicked_callback = function(this)
@@ -1205,7 +1205,7 @@ sm.widgets.page_control = dt.new_widget("box"){
sm.widgets.scripts = dt.new_widget("box"){
orientation = vertical,
dt.new_widget("label"){label = _("Scripts")},
dt.new_widget("label"){label = _("scripts")},
sm.widgets.category_selector,
sm.widgets.page_control,
table.unpack(sm.widgets.buttons)
@@ -1234,7 +1234,7 @@ sm.widgets.change_buttons = dt.new_widget("button"){
sm.widgets.configure = dt.new_widget("box"){
orientation = "vertical",
dt.new_widget("label"){label = _("Configuration")},
dt.new_widget("label"){label = _("configuration")},
sm.widgets.num_buttons,
sm.widgets.change_buttons,
}