From: Jo-Philipp Wich Date: Sun, 26 Jul 2009 22:48:09 +0000 (+0000) Subject: libs/web: implement i18n.string() and i18n.stringf() to obtain genuine Lua strings... X-Git-Tag: 0.10.0~1295 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1b557b0b7b2ebed0b8752ec3b676e801c6ba9043;p=oweals%2Fluci.git libs/web: implement i18n.string() and i18n.stringf() to obtain genuine Lua strings instead of udata objects --- diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index 091542f86..9a11a9dc8 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -111,3 +111,24 @@ end function translatef(key, default, ...) return tostring(translate(key, default)):format(...) end + +--- Return the translated value for a specific translation key +-- and ensure that the returned value is a Lua string value. +-- This is the same as calling tostring(translate(...)) +-- @param key Translation key +-- @param default Default translation +-- @return Translated string +function string(key, default) + return tostring(translate(key, default)) +end + +--- Return the translated value for a specific translation key and use it as sprintf pattern. +-- Ensure that the returned value is a Lua string value. +-- This is the same as calling tostring(translatef(...)) +-- @param key Translation key +-- @param default Default translation +-- @param ... Format parameters +-- @return Translated and formatted string +function stringf(key, default, ...) + return tostring(translate(key, default)):format(...) +end