From a04028037e8ba142737ff39ac5a2e78f07bc75c3 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 18 Oct 2018 10:54:12 +0200 Subject: luci-base: introduce luci.i18n.dump() Add a new luci.i18n.dump() function which returns all currently loaded translation strings as Lua table. Signed-off-by: Jo-Philipp Wich --- modules/luci-base/luasrc/i18n.lua | 6 ++++++ modules/luci-base/luasrc/i18n.luadoc | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/luci-base/luasrc/i18n.lua b/modules/luci-base/luasrc/i18n.lua index 968c387f12..42de832f7b 100644 --- a/modules/luci-base/luasrc/i18n.lua +++ b/modules/luci-base/luasrc/i18n.lua @@ -69,3 +69,9 @@ end function stringf(key, ...) return tostring(translate(key)):format(...) end + +function dump() + local rv = {} + tparser.get_translations(function(k, v) rv[k] = v end) + return rv +end diff --git a/modules/luci-base/luasrc/i18n.luadoc b/modules/luci-base/luasrc/i18n.luadoc index 13f10a1071..df6e38e5de 100644 --- a/modules/luci-base/luasrc/i18n.luadoc +++ b/modules/luci-base/luasrc/i18n.luadoc @@ -6,7 +6,6 @@ module "luci.i18n" ---[[ Clear the translation table. - @class function @name clear ]] @@ -26,6 +25,7 @@ Load a translation and copy its data into the translation table. Load a translation file using the default translation language. Alternatively load the translation of the fallback language. + @class function @name loadc @param file Language file @@ -62,9 +62,10 @@ Return the translated value for a specific translation key and use it as sprintf ---[[ 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(...)) + @class function @name string @param key Default translation text @@ -75,7 +76,9 @@ This is the same as calling tostring(translate(...)) 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(...)) + @class function @name stringf @param key Default translation text @@ -83,3 +86,12 @@ This is the same as calling tostring(translatef(...)) @return Translated and formatted string ]] +---[[ +Return all currently loaded translation strings as a key-value table. The key is the +hexadecimal representation of the translation key while the value is the translated +text content. + +@class function +@name dump +@return Key-value translation string table. +]] -- cgit v1.2.3