diff options
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 11 | ||||
-rw-r--r-- | libs/web/luasrc/i18n.lua | 20 |
2 files changed, 19 insertions, 12 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index e9d3b24d1..8d1e493fb 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -122,11 +122,12 @@ function dispatch() -- Init template engine local tpl = require("luci.template") - tpl.viewns.translate = function(...) return require("luci.i18n").translate(...) end - tpl.viewns.controller = luci.http.dispatcher() - tpl.viewns.uploadctrl = luci.http.dispatcher_upload() - tpl.viewns.media = luci.config.main.mediaurlbase - tpl.viewns.resource = luci.config.main.resourcebase + tpl.viewns.translate = function(...) return require("luci.i18n").translate(...) end + tpl.viewns.controller = luci.http.dispatcher() + tpl.viewns.uploadctrl = luci.http.dispatcher_upload() + tpl.viewns.media = luci.config.main.mediaurlbase + tpl.viewns.resource = luci.config.main.resourcebase + tpl.viewns.REQUEST_URI = luci.http.env.SCRIPT_NAME .. luci.http.env.PATH_INFO if c and type(c.target) == "function" then diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index 3a8a9a6c7..7ace708e9 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -29,6 +29,7 @@ require("luci.sys") table = {} i18ndir = luci.sys.libpath() .. "/i18n/" +loaded = {} -- Clears the translation table function clear() @@ -36,14 +37,19 @@ function clear() end -- Loads a translation and copies its data into the global translation table -function load(file) - local f = loadfile(i18ndir .. file) - if f then - setfenv(f, table) - f() - return true +function load(file, force) + if force or not loaded[file] then + local f = loadfile(i18ndir .. file) + if f then + setfenv(f, table) + f() + loaded[file] = true + return true + else + return false + end else - return false + return true end end |