From 09a50d0458f46c6129b4bea94502908241b3aed3 Mon Sep 17 00:00:00 2001 From: sapier Date: Wed, 14 Aug 2013 19:22:23 +0200 Subject: Add translation for main menu Add engine.gettext() and remove gettext() calls in guiFormspecMenu.cpp --- builtin/misc_helpers.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'builtin/misc_helpers.lua') 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 @@ -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 -- cgit v1.2.3