summaryrefslogtreecommitdiff
path: root/builtin/misc_helpers.lua
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-08-14 19:22:23 +0200
committerPilzAdam <pilzadam@minetest.net>2013-08-17 16:01:43 +0200
commit09a50d0458f46c6129b4bea94502908241b3aed3 (patch)
tree57a2094750b7d47446a05fe1f8a64a8bca490fe8 /builtin/misc_helpers.lua
parent787b43b2183262a08726434e2597638ad85bfb72 (diff)
downloadminetest-09a50d0458f46c6129b4bea94502908241b3aed3.tar.gz
minetest-09a50d0458f46c6129b4bea94502908241b3aed3.tar.bz2
minetest-09a50d0458f46c6129b4bea94502908241b3aed3.zip
Add translation for main menu
Add engine.gettext() and remove gettext() calls in guiFormspecMenu.cpp
Diffstat (limited to 'builtin/misc_helpers.lua')
-rw-r--r--builtin/misc_helpers.lua36
1 files changed, 34 insertions, 2 deletions
diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua
index 41d0e7c2f..3a325e0d3 100644
--- a/builtin/misc_helpers.lua
+++ b/builtin/misc_helpers.lua
@@ -86,14 +86,23 @@ function string:split(sep)
end
--------------------------------------------------------------------------------
+function file_exists(filename)
+ local f = io.open(filename, "r")
+ if f==nil then
+ return false
+ else
+ f:close()
+ return true
+ end
+end
+
+--------------------------------------------------------------------------------
function string:trim()
return (self:gsub("^%s*(.-)%s*$", "%1"))
end
assert(string.trim("\n \t\tfoo bar\t ") == "foo bar")
-
-
--------------------------------------------------------------------------------
function math.hypot(x, y)
local t
@@ -209,6 +218,29 @@ if engine ~= nil then
return nil
end
+
+ function fgettext(text, ...)
+ text = engine.gettext(text)
+ local arg = {n=select('#', ...), ...}
+ if arg.n >= 1 then
+ -- Insert positional parameters ($1, $2, ...)
+ result = ''
+ pos = 1
+ while pos <= text:len() do
+ newpos = text:find('[$]', pos)
+ if newpos == nil then
+ result = result .. text:sub(pos)
+ pos = text:len() + 1
+ else
+ paramindex = tonumber(text:sub(newpos+1, newpos+1))
+ result = result .. text:sub(pos, newpos-1) .. tostring(arg[paramindex])
+ pos = newpos + 2
+ end
+ end
+ text = result
+ end
+ return engine.formspec_escape(text)
+ end
end
--------------------------------------------------------------------------------
-- core only fct