elua: respect add-location / no-location options in xgettext
authorDaniel Kolesa <d.kolesa@samsung.com>
Fri, 30 May 2014 14:37:04 +0000 (15:37 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:52 +0000 (15:48 +0100)
src/bin/elua/apps/xgettext.lua
src/bin/elua/modules/xgettext/generator.lua

index 43e0b5298d4d907906f3a07b52836ec594fd0805..f02b887d0d747244258297845dadd7074a8fba8e 100644 (file)
@@ -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",
index 16c4ec2f9b604f7003a862a36e14e44315913672..3b7238c501c2ee208e131ad8fc5e8b284421dd5e 100644 (file)
@@ -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