1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
--
-- (C) 2013-22 - ntop.org
--
local icmp_utils = {}
local icmp_locale_loaded = false
local dirs = ntop.getDirs()
local function get_icmp_locale_path(locale)
local locale_path = dirs.installdir .. "/scripts/locales/icmp/" .. locale .. ".lua"
return locale_path
end
-- #######################
local function load_icmp_locale()
local to_load = {i18n.getLocale()}
if i18n.getFallbackLocale() ~= i18n.getLocale() then
to_load[#to_load + 1] = i18n.getFallbackLocale()
end
for _, cur_locale in ipairs(to_load) do
local cur_locale_path = get_icmp_locale_path(cur_locale)
if ntop.exists(cur_locale_path) then
i18n.load({
[cur_locale] = dofile(cur_locale_path)
})
end
end
-- tprint({cur = current_locale, fb = fallback_locale, selected = selected_locale, cane = i18n("icmp_v4_types.type_000")})
icmp_locale_loaded = true
end
-- #######################
function icmp_utils.get_icmp_type_label(ip_version, icmp_type)
local key = string.format("icmp_v%u_types.type_%u", ip_version, icmp_type)
local res = i18n(key)
return res or ""
end
-- #######################
function icmp_utils.get_icmp_code_label(ip_version, icmp_type, icmp_code)
local key = string.format("icmp_v%u_codes.type_%u.code_%u", ip_version, icmp_type, icmp_code)
local res = i18n(key)
return res or ""
end
-- #######################
function icmp_utils.get_icmp_label(ip_version, icmp_type, icmp_code)
if not icmp_locale_loaded then
load_icmp_locale()
end
local type_label = icmp_utils.get_icmp_type_label(ip_version, icmp_type)
local code_label = icmp_utils.get_icmp_code_label(ip_version, icmp_type, icmp_code)
if not isEmptyString(code_label) then
return code_label
else
return type_label
end
end
return icmp_utils
|