From 1b7c3e060bbd8edd995b51405f0e07493c9b6321 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 30 Apr 2015 23:48:07 +0200 Subject: [PATCH] gluon-luci-node-role: make node role display strings translatable --- docs/releases/v2015.1.rst | 13 +++++++++++++ docs/site-example/site.conf | 10 +++++----- docs/user/site.rst | 12 ++++++++---- package/gluon-luci-node-role/check_site.lua | 10 ++-------- .../usr/lib/lua/luci/model/cbi/admin/noderole.lua | 4 ++-- package/gluon-node-info/check_site.lua | 7 ------- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/docs/releases/v2015.1.rst b/docs/releases/v2015.1.rst index 17a3c80a..83a57666 100644 --- a/docs/releases/v2015.1.rst +++ b/docs/releases/v2015.1.rst @@ -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`` diff --git a/docs/site-example/site.conf b/docs/site-example/site.conf index e2c03434..a25857a9 100644 --- a/docs/site-example/site.conf +++ b/docs/site-example/site.conf @@ -154,13 +154,13 @@ }, -- Node roles - -- roles { + -- roles = { -- default = 'node', -- list = { - -- node = 'Normal Node', - -- test = 'Test Node', - -- backbone = 'Backbone Node', - -- service = 'Service Node', + -- 'node', + -- 'test', + -- 'backbone', + -- 'service', -- }, -- }, diff --git a/docs/user/site.rst b/docs/user/site.rst index f555bb7d..65c9022f 100644 --- a/docs/user/site.rst +++ b/docs/user/site.rst @@ -150,15 +150,19 @@ roles : optional ``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 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 = { default = 'node', list = { - node = 'Normal Node', - test = 'Test Node', - backbone = 'Backbone Node', - service = 'Service Node', + 'node', + 'test', + 'backbone', + 'service', }, }, diff --git a/package/gluon-luci-node-role/check_site.lua b/package/gluon-luci-node-role/check_site.lua index cd3ca937..ab01eeb5 100644 --- a/package/gluon-luci-node-role/check_site.lua +++ b/package/gluon-luci-node-role/check_site.lua @@ -1,8 +1,2 @@ -local function check_role(k, _) - local role = string.format('roles.list[%q]', k) - - need_string(role) -end - -need_string('roles.default') -need_table('roles.list', check_role) +need_string 'roles.default' +need_string_array 'roles.list' diff --git a/package/gluon-luci-node-role/files/usr/lib/lua/luci/model/cbi/admin/noderole.lua b/package/gluon-luci-node-role/files/usr/lib/lua/luci/model/cbi/admin/noderole.lua index d2ab51a7..e7832ad9 100644 --- a/package/gluon-luci-node-role/files/usr/lib/lua/luci/model/cbi/admin/noderole.lua +++ b/package/gluon-luci-node-role/files/usr/lib/lua/luci/model/cbi/admin/noderole.lua @@ -18,8 +18,8 @@ s = f:section(SimpleSection, nil, i18n.translate( o = s:option(ListValue, "role", i18n.translate("Role")) o.default = role o.rmempty = false -for role, prettyname in pairs(site.roles.list) do - o:value(role, prettyname) +for _, role in ipairs(site.roles.list) do + o:value(role, i18n.translate('gluon-luci-node-role:role:' .. role)) end function f.handle(self, state, data) diff --git a/package/gluon-node-info/check_site.lua b/package/gluon-node-info/check_site.lua index d8d46408..7e50edfc 100644 --- a/package/gluon-node-info/check_site.lua +++ b/package/gluon-node-info/check_site.lua @@ -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_table('roles.list', check_role, false)