mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add translation for main menu
Add engine.gettext() and remove gettext() calls in guiFormspecMenu.cpp
This commit is contained in:
parent
787b43b218
commit
09a50d0458
13 changed files with 241 additions and 224 deletions
|
@ -85,6 +85,17 @@ function string:split(sep)
|
|||
return fields
|
||||
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"))
|
||||
|
@ -92,8 +103,6 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue