diff --git a/scripts/lua/locale.lua b/scripts/lua/locale.lua index 009a9b7e6150..7d91aea03773 100644 --- a/scripts/lua/locale.lua +++ b/scripts/lua/locale.lua @@ -1,7 +1,6 @@ -- -- (C) 2013-24 - ntop.org -- - local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/locales/?.lua;" .. package.path @@ -12,12 +11,8 @@ local json = require "dkjson" -- ################################ local info = ntop.getInfo(false) -local lines = { - 'Cache-Control: public, max-age=3600', - 'Last-Modified: '..os.date("!%a, %m %B %Y %X %Z"), - 'Server: ntopng '..info["version"]..' ['.. info["platform"]..']', - 'Content-Type: text/javascript' -} +local lines = {'Cache-Control: public, max-age=3600', 'Last-Modified: ' .. os.date("!%a, %m %B %Y %X %Z"), + 'Server: ntopng ' .. info["version"] .. ' [' .. info["platform"] .. ']', 'Content-Type: text/javascript'} print("HTTP/1.1 200 OK\r\n" .. table.concat(lines, "\r\n") .. "\r\n\r\n") @@ -27,22 +22,31 @@ local language = _GET["user_language"] or "en" local main_language_path = require(language) -if(language ~= "en") then - local alt_language_path = require("en") +local function map_strings(main_language_path, alt_language_path) + -- Add missing strings using defaults (English) + for k, v in pairs(alt_language_path) do + if (main_language_path[k] == nil) then + main_language_path[k] = alt_language_path[k] + end + if type(main_language_path[k]) == "table" then + main_language_path[k] = map_strings(main_language_path[k], alt_language_path[k]) + end + end + return main_language_path +end - -- Add missing strings using defaults (English) - for k, v in pairs(alt_language_path) do - if(main_language_path[k] == nil) then - main_language_path[k] = alt_language_path[k] - end - end +if (language ~= "en") then + local alt_language_path = require("en") + -- Add missing strings using defaults (English) + map_strings(main_language_path, alt_language_path) end local info = ntop.getInfo(true) main_language_path["ntopng_release_info"] = getNtopngRelease(info) -print[[ const ntop_locale = ]] print(json.encode(main_language_path)) +print [[ const ntop_locale = ]] +print(json.encode(main_language_path)) -print[[; +print [[; function i18n(key) { var fields = key.split('.');