Browse Source

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

Matthias Schiffer 9 years ago
parent
commit
1b7c3e060b

+ 13 - 0
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``
 

+ 5 - 5
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',
   --   },
   -- },
 

+ 8 - 4
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',
         },
       },
 

+ 2 - 8
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'

+ 2 - 2
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)

+ 0 - 7
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)