diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-31 15:42:07 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-31 15:42:07 +0000 |
commit | 8f2a3f1dccee6a0b7ca99ac24458aa9c8987e131 (patch) | |
tree | f346f241f4ab155f5be542503757504e43f4c81b /libs/web/luasrc/i18n.lua | |
parent | 7f92fa405cee6b2657325a4b7554be88b217fb9f (diff) |
libs/web: prepare template parser, dispatcher and i18n class for upcoming po format change
Diffstat (limited to 'libs/web/luasrc/i18n.lua')
-rw-r--r-- | libs/web/luasrc/i18n.lua | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index 9a11a9dc8..816d90310 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -93,42 +93,38 @@ function setlanguage(lang) end --- Return the translated value for a specific translation key. --- @param key Translation key --- @param def Default translation +-- @param key Default translation text -- @return Translated string -function translate(key, def) +function translate(key) return (table[context.lang] and table[context.lang][key]) or (table[context.parent] and table[context.parent][key]) or (table[default] and table[default][key]) - or def + or key end --- Return the translated value for a specific translation key and use it as sprintf pattern. --- @param key Translation key --- @param default Default translation +-- @param key Default translation text -- @param ... Format parameters -- @return Translated and formatted string -function translatef(key, default, ...) - return tostring(translate(key, default)):format(...) +function translatef(key, ...) + return tostring(translate(key)):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 +-- @param key Default translation text -- @return Translated string -function string(key, default) - return tostring(translate(key, default)) +function string(key) + return tostring(translate(key)) 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 key Default translation text -- @param ... Format parameters -- @return Translated and formatted string -function stringf(key, default, ...) - return tostring(translate(key, default)):format(...) +function stringf(key, ...) + return tostring(translate(key)):format(...) end |