gluon-luci-node-role: make node role display strings translatable

This commit is contained in:
Matthias Schiffer 2015-04-30 23:48:07 +02:00
parent 82983c871e
commit 1b7c3e060b
6 changed files with 30 additions and 26 deletions

View File

@ -39,6 +39,19 @@ Site changes
} }
} }
- ``roles``: The display strings for the node roles aren't configured in the ``site.conf`` anymore, but
in the site i18n files. The ``site.conf`` section becomes::
roles = {
default = 'foo',
list = {
'foo',
'bar',
}
}
The display string use i18n message IDs like ``gluon-luci-node-role:role:foo`` and ``gluon-luci-node-role:role:bar``.
* ``site.mk`` * ``site.mk``

View File

@ -154,13 +154,13 @@
}, },
-- Node roles -- Node roles
-- roles { -- roles = {
-- default = 'node', -- default = 'node',
-- list = { -- list = {
-- node = 'Normal Node', -- 'node',
-- test = 'Test Node', -- 'test',
-- backbone = 'Backbone Node', -- 'backbone',
-- service = 'Service Node', -- 'service',
-- }, -- },
-- }, -- },

View File

@ -150,15 +150,19 @@ roles : optional
``default`` takes the default role which is set initially. This value should be ``default`` takes the default role which is set initially. This value should be
part of ``list``. If you want node owners to change the role via config mode add part of ``list``. If you want node owners to change the role via config mode add
the package ``gluon-luci-node-role`` to ``site.mk``. the package ``gluon-luci-node-role`` to ``site.mk``.
The strings to display in the LuCI interface can be configured per language in the
``i18n/en.po``, ``i18n/de.po``, etc. files of the site repository using message IDs like
``gluon-luci-node-role:role:node`` and ``gluon-luci-node-role:role:backbone``.
:: ::
roles = { roles = {
default = 'node', default = 'node',
list = { list = {
node = 'Normal Node', 'node',
test = 'Test Node', 'test',
backbone = 'Backbone Node', 'backbone',
service = 'Service Node', 'service',
}, },
}, },

View File

@ -1,8 +1,2 @@
local function check_role(k, _) need_string 'roles.default'
local role = string.format('roles.list[%q]', k) need_string_array 'roles.list'
need_string(role)
end
need_string('roles.default')
need_table('roles.list', check_role)

View File

@ -18,8 +18,8 @@ s = f:section(SimpleSection, nil, i18n.translate(
o = s:option(ListValue, "role", i18n.translate("Role")) o = s:option(ListValue, "role", i18n.translate("Role"))
o.default = role o.default = role
o.rmempty = false o.rmempty = false
for role, prettyname in pairs(site.roles.list) do for _, role in ipairs(site.roles.list) do
o:value(role, prettyname) o:value(role, i18n.translate('gluon-luci-node-role:role:' .. role))
end end
function f.handle(self, state, data) function f.handle(self, state, data)

View File

@ -1,8 +1 @@
local function check_role(k, _)
local role = string.format('roles.list[%q]', k)
need_string(role)
end
need_string('roles.default', false) need_string('roles.default', false)
need_table('roles.list', check_role, false)