* luci/core: cbi.lua: automatic i18n capabilities; whitespace cleanup
This commit is contained in:
parent
6250394740
commit
47b62843fc
1 changed files with 99 additions and 75 deletions
|
@ -2,7 +2,7 @@
|
|||
LuCI - Configuration Bind Interface
|
||||
|
||||
Description:
|
||||
Offers an interface for binding confiugration values to certain
|
||||
Offers an interface for binding configuration values to certain
|
||||
data types. Supports value and range validation and basic dependencies.
|
||||
|
||||
FileId:
|
||||
|
@ -75,6 +75,22 @@ function Node.__init__(self, title, description)
|
|||
self.template = "cbi/node"
|
||||
end
|
||||
|
||||
-- i18n helper
|
||||
function Node._i18n(self, config, section, option, title, description)
|
||||
|
||||
-- i18n loaded?
|
||||
if type(luci.i18n) == "table" then
|
||||
|
||||
local key = config:gsub("[^%w]+", "")
|
||||
|
||||
if section then key = key .. "_" .. section:lower():gsub("[^%w]+", "") end
|
||||
if option then key = key .. "_" .. option:lower():gsub("[^%w]+", "") end
|
||||
|
||||
self.title = title or luci.i18n.translate( key, option or section or config )
|
||||
self.description = description or luci.i18n.translate( key .. "_desc", "" )
|
||||
end
|
||||
end
|
||||
|
||||
-- Append child nodes
|
||||
function Node.append(self, obj)
|
||||
table.insert(self.children, obj)
|
||||
|
@ -121,6 +137,8 @@ Map = class(Node)
|
|||
|
||||
function Map.__init__(self, config, ...)
|
||||
Node.__init__(self, ...)
|
||||
Node._i18n(self, config, nil, nil, ...)
|
||||
|
||||
self.config = config
|
||||
self.template = "cbi/map"
|
||||
self.uci = luci.model.uci.Session()
|
||||
|
@ -138,9 +156,12 @@ function Map.parse(self, ...)
|
|||
end
|
||||
|
||||
-- Creates a child section
|
||||
function Map.section(self, class, ...)
|
||||
function Map.section(self, class, section, ...)
|
||||
if instanceof(class, AbstractSection) then
|
||||
local obj = class(self, ...)
|
||||
local obj = class(self, section, ...)
|
||||
|
||||
Node._i18n(obj, self.config, section, nil, ...)
|
||||
|
||||
self:append(obj)
|
||||
return obj
|
||||
else
|
||||
|
@ -225,9 +246,12 @@ function AbstractSection.__init__(self, map, sectiontype, ...)
|
|||
end
|
||||
|
||||
-- Appends a new option
|
||||
function AbstractSection.option(self, class, ...)
|
||||
function AbstractSection.option(self, class, option, ...)
|
||||
if instanceof(class, AbstractValue) then
|
||||
local obj = class(self.map, ...)
|
||||
local obj = class(self.map, option, ...)
|
||||
|
||||
Node._i18n(obj, self.config, self.section, option, ...)
|
||||
|
||||
self:append(obj)
|
||||
return obj
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue