diff options
| -rw-r--r-- | gettext.lua | 11 | ||||
| -rw-r--r-- | init.lua | 10 | ||||
| -rw-r--r-- | lib.lua | 2 | ||||
| -rwxr-xr-x | tools/findtext.lua | 2 | ||||
| -rw-r--r-- | tools/updatetext.lua | 22 | 
5 files changed, 17 insertions, 30 deletions
| diff --git a/gettext.lua b/gettext.lua index dff4ec3..a2e0eca 100644 --- a/gettext.lua +++ b/gettext.lua @@ -1,7 +1,6 @@  local strfind, strsub, strrep = string.find, string.sub, string.rep  local strmatch, strgsub = string.match, string.gsub -local floor = math.floor  local function split(str, sep)  	local pos, endp = 1, #str+1 @@ -103,6 +102,7 @@ local function parse_po(str)  		return perror("malformed line") +	-- luacheck: ignore  	until true end -- end for  	return texts @@ -110,9 +110,6 @@ end  local M = { } -local domains = { } -local dgettext_cache = { } -local dngettext_cache = { }  local langs  local function detect_languages() @@ -166,8 +163,8 @@ end  -- Note that it assumes the C expression is valid to begin with.  local function compile_plural_forms(str)  	local plural = strmatch(str, "plural=([^;]+);?$") -	local function replace_ternary(str) -		local c, t, f = strmatch(str, "^(.-)%?(.-):(.*)") +	local function replace_ternary(s) +		local c, t, f = strmatch(s, "^(.-)%?(.-):(.*)")  		if c then  			return ("__if("  					..replace_ternary(c) @@ -175,7 +172,7 @@ local function compile_plural_forms(str)  					..","..replace_ternary(f)  					..")")  		end -		return str +		return s  	end  	plural = replace_ternary(plural)  	plural = strgsub(plural, "&&", " and ") @@ -86,7 +86,7 @@ end  local function catngettext(catalogs, msgid, msgid_plural, n)  	n = math.floor(n) -	for i, cat in ipairs(catalogs) do +	for _, cat in ipairs(catalogs) do  		local msgstr = cat and cat[msgid]  		if msgstr then  			local index = cat.plural_index(n) @@ -107,18 +107,18 @@ function intllib.make_gettext_pair(modname)  	local localedir = minetest.get_modpath(modname).."/locale"  	local catalogs = gettext.load_catalogs(localedir)  	local getter = Getter(modname) -	local function gettext(msgid, ...) +	local function gettext_func(msgid, ...)  		local msgstr = (catgettext(catalogs, msgid)  				or getter(msgid))  		return do_replacements(msgstr, ...)  	end -	local function ngettext(msgid, msgid_plural, n, ...) +	local function ngettext_func(msgid, msgid_plural, n, ...)  		local msgstr = (catngettext(catalogs, msgid, msgid_plural, n)  				or getter(msgid))  		return do_replacements(msgstr, ...)  	end -	gettext_getters[modname] = { gettext, ngettext } -	return gettext, ngettext +	gettext_getters[modname] = { gettext_func, ngettext_func } +	return gettext_func, ngettext_func  end @@ -49,7 +49,7 @@ end  function intllib.load_strings(filename)  	local file, err = io.open(filename, "r")  	if not file then -		return nil +		return nil, err  	end  	local strings = {}  	for line in file:lines() do diff --git a/tools/findtext.lua b/tools/findtext.lua index b6360cb..e5f6e88 100755 --- a/tools/findtext.lua +++ b/tools/findtext.lua @@ -123,7 +123,7 @@ table.sort(messages)  local last_msg -for i, msg in ipairs(messages) do +for _, msg in ipairs(messages) do  	if msg ~= last_msg then  		printf("%s =\n", escape(msg))  	end diff --git a/tools/updatetext.lua b/tools/updatetext.lua index 00f9bf6..5d5734b 100644 --- a/tools/updatetext.lua +++ b/tools/updatetext.lua @@ -7,7 +7,7 @@ end  if basedir == "" then basedir = "./" end  -- Required by load_strings() -function string.trim(s) +function string.trim(s) -- luacheck: ignore  	return s:gsub("^%s*(.-)%s*$", "%1")  end @@ -20,7 +20,7 @@ local function err(fmt, ...)  	os.exit(1)  end -local template +local output, outfile, template  local catalogs = { }  local function usage() @@ -54,10 +54,7 @@ while i <= #arg do  		if i > #arg then  			err("missing required argument to `%s'", a)  		end -	elseif (a == "-c") or (a == "--comment") then -		old_msg_mode = "c" -	elseif (a == "-d") or (a == "--delete") then -		old_msg_mode = "d" +		output = arg[i]  	elseif a:sub(1, 1) ~= "-" then  		if not template then  			template = a @@ -81,27 +78,18 @@ if not f then  	err("error opening template: %s", e)  end -local function printf(fmt, ...) -	outfile:write(fmt:format(...)) -end -  local escapes = { ["\n"] = "\\n", ["="] = "\\=", ["\\"] = "\\\\", }  local function escape(s)  	return s:gsub("[\\\n=]", escapes)  end  if output then -	local e  	outfile, e = io.open(output, "w")  	if not outfile then  		err("error opening file for writing: %s", e)  	end  end -local function printf(fmt, ...) -	io.stdout:write(fmt:format(...)) -end -  local template_msgs = intllib.load_strings(template)  for _, file in ipairs(catalogs) do @@ -120,10 +108,12 @@ for _, file in ipairs(catalogs) do  		for k, v in pairs(catalog_msgs) do  			if not template_msgs[k] then  				print("OLD: "..k) +				table.insert(dirty_lines, "OLD: "..escape(k).." = "..escape(v))  			end  		end  		if #dirty_lines > 0 then -			local outf, e = io.open(file, "a+") +			local outf +			outf, e = io.open(file, "a+")  			if outf then  				outf:write("\n")  				for _, line in ipairs(dirty_lines) do | 
