From 80e7eca064213cb719bc13bd6137ded1754320e2 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 26 Sep 2018 23:59:42 -0400 Subject: [PATCH 1/3] Added tool to compile source translation files and place the results in the correct locale directory --- tools/gen_mo.lua | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tools/gen_mo.lua diff --git a/tools/gen_mo.lua b/tools/gen_mo.lua new file mode 100644 index 0000000..c69848a --- /dev/null +++ b/tools/gen_mo.lua @@ -0,0 +1,99 @@ +--[[ + gen_mo.lua - generate .mo files from .po files and put them in the correct place + + Copyright (C) 2016,2018 Bill Ferguson + + 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 . +]] +--[[ + gen_mo - generate translation files from the source and place them in the appropriate locale directory + + gen_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" + +-- 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("cd "..LUA_DIR..";find . -name \\*.po -print") + + 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_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, + } +) From 5c2c9e2a8fb5c0b848cf949c79d0ffa40bbfe240 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 12 Jan 2019 22:21:48 -0500 Subject: [PATCH 2/3] Changed name to gen_18n_mo to further clarify what the program does. --- tools/{gen_mo.lua => gen_i18n_mo.lua} | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename tools/{gen_mo.lua => gen_i18n_mo.lua} (96%) diff --git a/tools/gen_mo.lua b/tools/gen_i18n_mo.lua similarity index 96% rename from tools/gen_mo.lua rename to tools/gen_i18n_mo.lua index c69848a..a27efe3 100644 --- a/tools/gen_mo.lua +++ b/tools/gen_i18n_mo.lua @@ -50,8 +50,6 @@ if msgfmt_executable then find_cmd = "dir /b/s " .. LUA_DIR .. "\\*.po" end - -- local output = io.popen("cd "..LUA_DIR..";find . -name \\*.po -print") - local output = io.popen(find_cmd) -- for each .po file.... @@ -88,7 +86,7 @@ else end dt.preferences.register("executable_paths", "msgfmt", -- name "file", -- type - 'gen_mo: msgfmt location', -- label + 'gen_i18n_mo: msgfmt location', -- label 'Install location of msgfmt. Requires restart to take effect.', -- tooltip "msgfmt", -- default dt.new_widget("file_chooser_button"){ From 68b5acc154ed297988328b7173c855e301f765d2 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 12 Jan 2019 22:27:06 -0500 Subject: [PATCH 3/3] Updated comments to reflect name change --- tools/gen_i18n_mo.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/gen_i18n_mo.lua b/tools/gen_i18n_mo.lua index a27efe3..d3b5b5b 100644 --- a/tools/gen_i18n_mo.lua +++ b/tools/gen_i18n_mo.lua @@ -1,5 +1,5 @@ --[[ - gen_mo.lua - generate .mo files from .po files and put them in the correct place + gen_18n_mo.lua - generate .mo files from .po files and put them in the correct place Copyright (C) 2016,2018 Bill Ferguson @@ -17,9 +17,9 @@ along with this program. If not, see . ]] --[[ - gen_mo - generate translation files from the source and place them in the appropriate locale directory + gen_i18n_mo - generate translation files from the source and place them in the appropriate locale directory - gen_mo finds all the .po files scattered throughout the script tree, compiles them into + 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. ]]