summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2016-11-05 16:17:37 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2016-11-05 16:17:37 +0000
commit69bf26b85f2186b11d2dcecc5b39cb2a5bfcdeaf (patch)
treee6c92a8609ec9778b172c73c76c2f58fdd55751a
parent42f9bd6388ef451495e8a17c7742f0987b91cab1 (diff)
downloadgitano-69bf26b85f2186b11d2dcecc5b39cb2a5bfcdeaf.tar.gz
i18n work for gitano.util
-rw-r--r--lang/en.lua24
-rw-r--r--lib/gitano/util.lua52
2 files changed, 54 insertions, 22 deletions
diff --git a/lang/en.lua b/lang/en.lua
index 1f0fdd3..46ef0c2 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -206,4 +206,28 @@ example administration repository rules and an admin user and group.
DEBUG_ATTEMPT_LOADSTRING = "Attempting to loadstring in the sandbox",
DEBUG_SET_GLOBALS = "Setting globals in supple sandbox",
DEBUG_SUPPLE_HOST_RUN = "Entering supple.host.run()",
+
+ -- Messages from the util module
+ DEBUG_WELCOME_TO = "Welcome to ${site}",
+ DEBUG_RUNNING = "Running:",
+ DEBUG_ON_BEHALF_OF = "On behalf of ${user} using key ${key}",
+ ERROR_RUNNING_COMMAND = "Error running ${cmd}: ${reason}",
+ UNABLE_TO_CONTINUE = "Unable to continue",
+ MSG_COMPLETED_SUCCESSFULLY = "${cmd} completed successfully",
+ WARN_UNTERMINATED_STRING = "Un-terminated quoted string",
+ WARN_UNUSED_ESCAPE = "Un-used escape at end",
+ WARN_NO_COMMAND = "No command found?",
+ ERROR_STAT_FILE_FAILED = "Stat file ${file} failed: ${reason}",
+ ERROR_NO_CB = "No callback provided",
+ MSG_SKIPPING_FILE = "Skipping file ${file}",
+ MSG_COPYING_FILE = "Copying file ${from} to ${to}",
+ ERROR_COPY_FILE_FAILED = "Copy file ${from} to ${to} failed: ${reason}",
+ MSG_COPY_SYMLINK = "Copying symlink ${from} to ${to}",
+ ERROR_COPY_SYMLINK_FAILED = "Copy symlink ${from} to ${to} failed: ${reason}",
+ MSG_COPY_DIR = "Copying dir ${from} to ${to}",
+ ERROR_COPY_DIR_FAILED = "Copy dir ${from} to ${to} failed: ${reason}",
+ ERROR_UNSUPPORTED_TYPE = "Unsupported file type ${type} during copy",
+ ERROR_EXPECTED_TAG_NAME = "Expected tag name in string expansion of ${...}",
+ ERROR_UNTERMINATED_TAG = "Unterminated tag expansion in string.",
+ ERROR_LOOP_IN_EXPN = "Loop detected in tag expansion",
}
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua
index 2e80d68..2581eb0 100644
--- a/lib/gitano/util.lua
+++ b/lib/gitano/util.lua
@@ -9,6 +9,7 @@
local luxio = require 'luxio'
local sio = require 'luxio.simple'
local log = require 'gitano.log'
+local i18n = require 'gitano.i18n'
local scrypt = require 'scrypt'
local tconcat = table.concat
@@ -17,22 +18,24 @@ local check_password = scrypt.verify_password
local function run_command(cmd, cmdline, parsed_cmdline, user,
config, env, repo)
- log.debug("Welcome to " .. config.global.site_name)
- log.debug("Running:")
+ log.debug(i18n.expand("DEBUG_WELCOME_TO", {site=config.global.site_name}))
+ log.debug(i18n.expand("DEBUG_RUNNING"))
for i = 1, #parsed_cmdline do
log.debug(" => " .. parsed_cmdline[i])
end
log.debug("")
- log.debug("On behalf of " .. user .. " using key " .. env["GITANO_KEYTAG"])
+ log.debug(i18n.expand("DEBUG_ON_BEHALF_OF", {user=user, key=env["GITANO_KEYTAG"]}))
local how, why = cmd.run(config, repo, parsed_cmdline, env)
if how ~= "exit" or why ~= 0 then
- log.critical("Error running " .. parsed_cmdline[1] .. ": " .. how)
- log.critical("Unable to continue")
+ log.critical(i18n.expand("ERROR_RUNNING_COMMAND",
+ {cmd=parsed_cmdline[1], reason=how}))
+ log.critical(i18n.expand("UNABLE_TO_CONTINUE"))
return why
else
- log.syslog.info(cmdline, "completed successfully")
+ log.syslog.info(i18n.expand("MSG_COMPLETED_SUCCESSFULLY",
+ {cmd=cmdline}))
return 0
end
end
@@ -116,13 +119,13 @@ local function _parse_cmdline(cmdline)
local warnings = {}
if quoting then
- warnings[#warnings+1] = "Un-terminated quoted string"
+ warnings[#warnings+1] = i18n.expand("WARN_UNTERMINATED_STRING")
end
if escaping then
- warnings[#warnings+1] = "Un-used escape at end"
+ warnings[#warnings+1] = i18n.expand("WARN_UNUSED_ESCAPE")
end
if #r == 0 then
- warnings[#warnings+1] = "No command found?"
+ warnings[#warnings+1] = i18n.expand("WARN_NO_COMMAND")
end
return r, warnings
@@ -322,7 +325,8 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
-- Stat and translate mode to type if type unknown
local stat, err = sio.lstat(filefrom)
if not stat then
- log.critical("Stat file", filefrom, "failed:", err)
+ log.critical(i18n.expand("ERROR_STAT_FILE_FAILED",
+ {file=filefrom, reason=err}))
return false, err
end
fileinfo.d_type = ({
@@ -338,33 +342,37 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
local fileto = path_join(to, filename)
local copycb = copy_cbs[fileinfo.d_type]
if not copycb then
- return false, "No callback provided"
+ return false, i18n.expand("ERROR_NO_CB")
end
if filter_cb(from, filename, fileinfo) then
- log.ddebug("Skipping file", filename)
+ log.ddebug(i18n.expand("MSG_SKIPPING_FILE", {file=filename}))
elseif fileinfo.d_type == luxio.DT_REG then
- log.ddebug("Copying file", filefrom, "to", fileto)
+ log.ddebug(i18n.expand("MSG_COPYING_FILE", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical("Copy file", filefrom, "to", fileto, "failed:", err)
+ log.critical(i18n.expand("ERROR_COPY_FILE_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_LNK then
- log.ddebug("Copying symlink", filefrom, "to", fileto)
+ log.ddebug(i18n.expand("MSG_COPYING_SYMLINK", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical("Copy symlink", filefrom, "to", fileto, "failed:", err)
+ log.critical(i18n.expand("ERROR_COPY_SYMLINK_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_DIR then
- log.ddebug("Copying dir", filefrom, "to", fileto)
+ log.ddebug(i18n.expand("MSG_COPYING_DIR", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto, copy_cbs, filter_cb)
if not ret then
- log.critical("Copy dir", filefrom, "to", fileto, "failed:", err)
+ log.critical(i18n.expand("ERROR_COPY_DIR_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return ret, err
end
else
- return false, ("Unsupported file type %d"):format(fileinfo.d_type)
+ return false, i18n.expand("ERROR_UNSUPPORTED_TYPE",
+ {type=tostring(fileinfo.d_type)})
end
end
return true
@@ -423,7 +431,7 @@ local function prep_expansion(str)
elseif seen == "{" then
if c == "}" then
seen = false
- assert(acc:match(tagname_pattern), "Expected tag name in string expansion of ${...}")
+ assert(acc:match(tagname_pattern), i18n.expand("ERROR_EXPECTED_TAG_NAME"))
ret[#ret+1] = { acc }
acc = ""
else
@@ -434,7 +442,7 @@ local function prep_expansion(str)
if seen == "$" then
acc = acc .. seen
elseif seen ~= false then
- error("Unterminated tag expansion in string.")
+ error(i18n.expand("ERROR_UNTERMINATED_TAG"))
end
if acc ~= "" then
ret[#ret+1] = acc
@@ -461,7 +469,7 @@ local function process_expansion(tags, expn, tagsactive)
else
elem = elem[1]
if tagsactive[elem] then
- return do_deny(tags, "Loop detected in tag expansion")
+ return do_deny(tags, i18n.expand("ERROR_LOOP_IN_EXPN"))
end
local tag = tags[elem]
if type(tag) == "function" then