From 1b557b0b7b2ebed0b8752ec3b676e801c6ba9043 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 26 Jul 2009 22:48:09 +0000 Subject: [PATCH] libs/web: implement i18n.string() and i18n.stringf() to obtain genuine Lua strings instead of udata objects --- libs/web/luasrc/i18n.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- 2.25.1