Skip to content

Commit

Permalink
Fixes locales not working front end size
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Jun 28, 2024
1 parent 59b8f98 commit ff7a96f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions scripts/lua/locale.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand All @@ -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('.');
Expand Down

0 comments on commit ff7a96f

Please sign in to comment.