summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-07-26 22:48:09 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-07-26 22:48:09 +0000
commit1b557b0b7b2ebed0b8752ec3b676e801c6ba9043 (patch)
treecaaca8bab94d13544bd3dd230268d88baab588aa
parentdebfd75f3384cac10939c62c2f884ae3c1a8cb4e (diff)
libs/web: implement i18n.string() and i18n.stringf() to obtain genuine Lua strings instead of udata objects
-rw-r--r--libs/web/luasrc/i18n.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua
index 091542f860..9a11a9dc8f 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 <code>tostring(translate(...))</code>
+-- @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 <code>tostring(translatef(...))</code>
+-- @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