From 7950c559651d5be074b2677d54b282c5dabdc1b0 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 30 May 2014 15:37:04 +0100 Subject: [PATCH] elua: respect add-location / no-location options in xgettext --- src/bin/elua/apps/xgettext.lua | 10 +++++++--- src/bin/elua/modules/xgettext/generator.lua | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bin/elua/apps/xgettext.lua b/src/bin/elua/apps/xgettext.lua index 43e0b52..f02b887 100644 --- a/src/bin/elua/apps/xgettext.lua +++ b/src/bin/elua/apps/xgettext.lua @@ -19,6 +19,8 @@ local flags = {} local opts_final = {} local opts_nolua = {} +local add_loc = true + local opts, args = getopt.parse { usage = "Usage: %prog [OPTION] [INPUTFILE]...", args = arg, @@ -111,10 +113,12 @@ local opts, args = getopt.parse { .. "style", opts = opts_final }, { nil, "no-location", false, help = "do not write '#: filename:line' " - .. "lines", opts = opts_nolua + .. "lines", opts = opts_nolua, + callback = function() add_loc = false end }, { "n", "add-location", false, help = "generate '#: filename:line' " - .. "lines (default)", opts = opts_nolua + .. "lines (default)", opts = opts_nolua, + callback = function() add_loc = true end }, { nil, "strict", false, help = "write out strict Uniforum " .. "conforming .po file", opts = opts_final @@ -373,7 +377,7 @@ for i, fname in ipairs(input_files) do f:close() end parsed_files[#parsed_files + 1] = generator.init(fpath, fcontents, - keywords, flags, opts) + keywords, flags, add_loc, opts) else args_nolua[#args_nolua] = fname local f = assert(cutil.popenv(hasxgettext, "r", diff --git a/src/bin/elua/modules/xgettext/generator.lua b/src/bin/elua/modules/xgettext/generator.lua index 16c4ec2..3b7238c 100644 --- a/src/bin/elua/modules/xgettext/generator.lua +++ b/src/bin/elua/modules/xgettext/generator.lua @@ -86,7 +86,7 @@ local gen_line_info = function(chunkname, lines) return tconc(linestrs, "\n") end -return { init = function(chunkname, input, keywords, flags, opts) +return { init = function(chunkname, input, keywords, flags, add_loc, opts) local rets = {} for i, msg in ipairs(gen_grouped_messages(parser.init(chunkname, input, keywords, flags, opts))) do @@ -100,7 +100,9 @@ return { init = function(chunkname, input, keywords, flags, opts) if msg.context then ret[#ret + 1] = "msgctxt " .. gen_message(msg.context) end - ret[#ret + 1] = gen_line_info(chunkname, msg.lines) + if add_loc then + ret[#ret + 1] = gen_line_info(chunkname, msg.lines) + end ret[#ret + 1] = "msgid " .. gen_message(msg[1]) local spf, ssf = opts["m"], opts["M"] if msg[2] then -- 2.7.4