* luci/statistics: implement initial i18n support, added first translations, removed...
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 28 May 2008 22:34:26 +0000 (22:34 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 28 May 2008 22:34:26 +0000 (22:34 +0000)
12 files changed:
applications/luci-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
applications/luci-statistics/luasrc/i18n/statistics.en [new file with mode: 0644]
applications/luci-statistics/luasrc/statistics/i18n.lua [new file with mode: 0644]
applications/luci-statistics/luasrc/statistics/rrdtool.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua
applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua

index 067428b46d1c385ffa1620642cae3f757078097a..871a3585ed3f518906b53e8a97e7d025868ce867 100644 (file)
@@ -44,7 +44,7 @@ function index()
 
        
        -- public views
-       entry({"freifunk", "statistics"},                       call("statistics_index"),               "Statistiken",          80)
+       entry({"freifunk", "statistics"},                       call("statistics_index"),               "Statistiken",          80).i18n = "statistics"
        
        for i, plugin in ipairs( data:plugins() ) do
                _entry({"freifunk", "statistics", plugin},      call("statistics_render"),              plugin,                  i)
@@ -99,7 +99,7 @@ function statistics_render()
 
        for i, inst in ipairs( data:plugin_instances( plugin ) ) do
                local graph = rrd.Graph()
-               for i, img in ipairs( graph:render( "OpenWrt", plugin, inst ) ) do
+               for i, img in ipairs( graph:render( plugin, inst ) ) do
                        table.insert( images, img )
                end
        end
diff --git a/applications/luci-statistics/luasrc/i18n/statistics.en b/applications/luci-statistics/luasrc/i18n/statistics.en
new file mode 100644 (file)
index 0000000..3c7514a
--- /dev/null
@@ -0,0 +1,57 @@
+stat_dg_title_wireless__signal_noise = "%H: Wireless - Signal Noise Ratio"
+stat_dg_label_wireless__signal_noise = "dBm"
+stat_ds_signal_noise = "Noise Level"
+stat_ds_signal_power = "Signal Strength"
+
+stat_dg_title_wireless__signal_quality = "%H: Wireless - Signal Quality"
+stat_dg_label_wireless__signal_quality = "n"
+stat_ds_signal_quality = "Signal Quality"
+
+stat_dg_title_ping = "%H: ICMP Roundtrip Times"
+stat_dg_label_ping = "ms"
+stat_ds_ping = "%di"
+
+stat_dg_title_iptables__ipt_packets = "%H: Firewall - Processed Packets"
+stat_dg_label_iptables__ipt_packets = "Packets/s"
+stat_ds_ipt_packets = 'Chain "%di"'
+
+stat_dg_title_netlink__if_octets = "%H: Netlink - Transfer on %pi"
+stat_dg_label_netlink__if_octets = "Bytes/s"
+stat_ds_if_octets = "Bytes (%ds)"
+
+stat_dg_title_netlink__if_packets = "%H: Netlink - Packets on %pi"
+stat_dg_label_netlink__if_packets = "Packets/s"
+stat_ds_if_packets = "Processed (%ds)"
+stat_ds_if_dropped = "Dropped   (%ds)"
+stat_ds_if_errors  = "Errors    (%ds)"
+
+stat_dg_title_netlink__if_multicast = "%H: Netlink - Multicast on %pi"
+stat_dg_label_netlink__if_multicast = "Packets/s"
+stat_ds_if_multicast = "Packets"
+
+stat_dg_title_netlink__if_collisions = "%H: Netlink - Collisions on %pi"
+stat_dg_label_netlink__if_collisions = "Collisions/s"
+stat_ds_if_collisions = "Collisions"
+
+stat_dg_title_netlink__if_tx_errors = "%H: Netlink - Errors on %pi"
+stat_dg_label_netlink__if_tx_errors = "Errors/s"
+stat_ds_if_tx_errors = "%di"
+stat_ds_if_rx_errors = "%di"
+
+stat_dg_title_processes = "%H: Processes"
+stat_dg_label_processes = "Processes/s"
+stat_ds_ps_state = "%di"
+
+stat_dg_title_cpu = "%H: Usage on Processor #%pi"
+stat_dg_label_cpu = "%"
+stat_ds_cpu       = "%di"
+
+stat_dg_title_interface__if_octets = "%H: Transfer on %di"
+stat_dg_label_interface__if_octets = "Bytes/s"
+
+stat_dg_title_interface__if_packets = "%H: Packets on %di"
+stat_dg_label_interface__if_packets = "Packets/s"
+
+stat_dg_title_tcpconns  = "%H: TCP-Connections to Port %pi"
+stat_dg_label_tcpconns  = "Connections/s"
+stat_ds_tcp_connections = "%di"
diff --git a/applications/luci-statistics/luasrc/statistics/i18n.lua b/applications/luci-statistics/luasrc/statistics/i18n.lua
new file mode 100644 (file)
index 0000000..a31d126
--- /dev/null
@@ -0,0 +1,100 @@
+module("luci.statistics.i18n", package.seeall)
+
+require("luci.util")
+require("luci.i18n")
+
+
+Instance = luci.util.class()
+
+
+function Instance.__init__( self, graph )
+       self.i18n  = luci.i18n
+       self.graph = graph
+
+       -- XXX: compat hack
+       self.i18n.load("statistics.en")
+end
+
+function Instance._subst( self, str, val )
+       str = str:gsub( "%%H",  self.graph.opts.host or "" )
+       str = str:gsub( "%%pn", val.plugin or "" )
+       str = str:gsub( "%%pi", val.pinst  or "" )
+       str = str:gsub( "%%dt", val.dtype  or "" )
+       str = str:gsub( "%%di", val.dinst  or "" )
+       str = str:gsub( "%%ds", val.dsrc   or "" )
+
+       return str
+end
+
+function Instance.title( self, plugin, pinst, dtype, dinst )
+
+       local title = self.i18n.translate(
+               string.format( "stat_dg_title_%s_%s_%s", plugin, pinst, dtype ),
+               self.i18n.translate(
+                       string.format( "stat_dg_title_%s_%s", plugin, pinst ),
+                       self.i18n.translate(
+                               string.format( "stat_dg_title_%s__%s", plugin, dtype ),
+                               self.i18n.translate(
+                                       string.format( "stat_dg_title_%s", plugin ),
+                                       self.graph:_mkpath( plugin, pinst, dtype )
+                               )
+                       )
+               )
+       )
+
+       return self:_subst( title, { 
+               plugin = plugin,
+               pinst  = pinst,
+               dtype  = dtype,
+               dinst  = dinst
+       } )
+
+end
+
+function Instance.label( self, plugin, pinst, dtype, dinst )
+
+       local label = self.i18n.translate(
+               string.format( "stat_dg_label_%s_%s_%s", plugin, pinst, dtype ),
+               self.i18n.translate(
+                       string.format( "stat_dg_label_%s_%s", plugin, pinst ),
+                       self.i18n.translate(
+                               string.format( "stat_dg_label_%s__%s", plugin, dtype ),
+                               self.i18n.translate(
+                                       string.format( "stat_dg_label_%s", plugin ),
+                                       self.graph:_mkpath( plugin, pinst, dtype )
+                               )
+                       )
+               )
+       )
+
+       return self:_subst( label, { 
+               plugin = plugin,
+               pinst  = pinst,
+               dtype  = dtype,
+               dinst  = dinst
+       } )
+
+end
+
+function Instance.ds( self, source )
+
+       local label = self.i18n.translate(
+               string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
+               self.i18n.translate(
+                       string.format( "stat_ds_%s_%s", source.type, source.instance ),
+                       self.i18n.translate(
+                               string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
+                               self.i18n.translate(
+                                       string.format( "stat_ds_%s", source.type ),
+                                       source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
+                               )
+                       )
+               )
+       )
+
+       return self:_subst( label, { 
+               dtype = source.type,
+               dinst = source.instance,
+               dsrc  = source.ds
+       } )
+end
index 17ac48a5a74dd502c91ead48909204fb09e76afb..1fe57a225725ff24beec36b29259a2bf275f768b 100644 (file)
@@ -3,7 +3,7 @@ module("luci.statistics.rrdtool", package.seeall)
 require("luci.statistics.datatree")
 require("luci.statistics.rrdtool.colors")
 require("luci.statistics.rrdtool.definitions")
-require("luci.i18n")
+require("luci.statistics.i18n")
 require("luci.util")
 require("luci.fs")
 
@@ -17,7 +17,7 @@ function Graph.__init__( self, timespan, opts )
        self.colors = luci.statistics.rrdtool.colors.Instance()
        self.defs   = luci.statistics.rrdtool.definitions.Instance()
        self.tree   = luci.statistics.datatree.Instance()
-       self.i18n   = luci.i18n
+       self.i18n   = luci.statistics.i18n.Instance( self )
 
        -- options
        opts.rrasingle = opts.rrasingle or true         -- XXX: fixme (uci)
@@ -34,12 +34,9 @@ function Graph.__init__( self, timespan, opts )
 
        -- store options
        self.opts = opts
-
-       -- load language file
-       self.i18n.loadc("statistics")
 end
 
-function Graph.mktitle( self, plugin, plugin_instance, dtype, dtype_instance )
+function Graph._mkpath( self, plugin, plugin_instance, dtype, dtype_instance )
        local t = self.opts.host .. "/" .. plugin
        if type(plugin_instance) == "string" and plugin_instance:len() > 0 then
                t = t .. "-" .. plugin_instance
@@ -52,11 +49,17 @@ function Graph.mktitle( self, plugin, plugin_instance, dtype, dtype_instance )
 end
 
 function Graph.mkrrdpath( self, ... )
-       return string.format( "/tmp/%s.rrd", self:mktitle( ... ) )
+       return string.format( "/tmp/%s.rrd", self:_mkpath( ... ) )
 end
 
 function Graph.mkpngpath( self, ... )
-       return string.format( "/tmp/rrdimg/%s.png", self:mktitle( ... ) )
+       return string.format( "/tmp/rrdimg/%s.png", self:_mkpath( ... ) )
+end
+
+function Graph.mktitle( self, plugin, plugin_instance, dtype, dtype_instance )
+
+       -- try various strings to retrieve a diagram title from the langfile
+       return "XXX"
 end
 
 function Graph._forcelol( self, list )
@@ -366,7 +369,6 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
 
                                -- store values
                                _ti( _sources, {
-                                       title    = dsname,   -- XXX: fixme i18n (dopts.title || i18n || dname)
                                        rrd      = dopts.rrd     or self:mkrrdpath( plugin, plugin_instance, dtype, dinst ),
                                        color    = dopts.color   or self.colors:to_string( self.colors:random() ),
                                        flip     = dopts.flip    or false,
@@ -381,6 +383,10 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
                                } )
 
 
+                               -- generate datasource title
+                               _sources[#_sources].title = self.i18n:ds( _sources[#_sources] )
+
+
                                -- find longest name ...
                                if _sources[#_sources].title:len() > _longest_name then
                                        _longest_name = _sources[#_sources].title:len()
@@ -415,9 +421,9 @@ function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
                -- store title and vlabel
                -- XXX: i18n
                _ti( _args, "-t" )
-               _ti( _args, opts.title )
+               _ti( _args, opts.title  or self.i18n:title( plugin, plugin_instance, _sources[1].type, instance ) )
                _ti( _args, "-v" )
-               _ti( _args, opts.vlabel )
+               _ti( _args, opts.vlabel or self.i18n:label( plugin, plugin_instance, _sources[1].type, instance ) )
 
                -- store additional rrd options
                if opts.rrdopts then
index 5a2ac53ca70b1ec7f9ce6208b364d9fa7644d90a..bd002e12facddcadac21b22907592c1d3d8894ae 100644 (file)
@@ -3,12 +3,9 @@ module("luci.statistics.rrdtool.definitions.cpu.cpu",package.seeall)
 function rrdargs( graph, host, plugin, plugin_instance, dtype )
 
        return {
-               title  = "Prozessorauslastung",
-               vlabel = "%",
-
                data = {
-                       instances = {
-                               cpu = { "idle", "nice", "system", "user" }
+                       instances = { 
+                               cpu = { "idle", "user", "system", "nice" }
                        },
 
                        options = {
index 1b61ad68ec2b2894084f8070b34e472d1d41e391..0d812d6ec7831302e4ccbcecda13097f1aa64bca 100644 (file)
@@ -7,12 +7,6 @@ function rrdargs( graph, host, plugin, plugin_instance )
        --
        local traffic = {
 
-               -- diagram title
-               title   = "Verkehr",
-
-               -- vertical label
-               vlabel  = "Bytes/s",
-
                -- draw this diagram for each data instance
                per_instance = true,
 
@@ -45,12 +39,6 @@ function rrdargs( graph, host, plugin, plugin_instance )
        --
        local packets = {
 
-               -- diagram title
-               title   = "Pakete",
-
-               -- vertical label
-               vlabel  = "Pakete/s",
-
                -- draw this diagram for each data instance
                per_instance = true,
 
index 4551073225e843a4d46809e1f382a7ee3c69b820..2ab57e86223250e1f34200b79945f7efa9694992 100644 (file)
@@ -3,10 +3,7 @@ module("luci.statistics.rrdtool.definitions.iptables.ipt_packets", package.seeal
 function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
-               title  = "Firewall",
-               vlabel = "Pakete/s",
-
-               data   = { 
+               data = { 
                        options = {
                                ipt_packets = { total = true }
                        }
index 47594f0f80a641cc61c357d8f207e3fc4649934d..8f32ab3d1e9a198d014ec4a85a515d222072c7ba 100644 (file)
@@ -7,12 +7,6 @@ function rrdargs( graph, plugin, plugin_instance )
        --
        local traffic = {
 
-               -- diagram title
-               title   = "Verkehr",
-
-               -- vertical label
-               vlabel  = "Bytes/s",
-
                -- diagram data description
                data = {
                        -- defined sources for data types, if ommitted assume a single DS named "value" (optional)
@@ -42,12 +36,6 @@ function rrdargs( graph, plugin, plugin_instance )
        --
        local packets = {
 
-               -- diagram title
-               title   = "Pakete",
-
-               -- vertical label
-               vlabel  = "Pakete/s",
-
                -- diagram data description
                data = {
                        -- data type order
@@ -116,12 +104,6 @@ function rrdargs( graph, plugin, plugin_instance )
        --
        local multicast = {
 
-               -- diagram title
-               title   = "Multicast-Pakete",
-
-               -- vertical label
-               vlabel  = "Pakete/s",
-
                -- diagram data description
                data = {
                        -- data type order
@@ -144,12 +126,6 @@ function rrdargs( graph, plugin, plugin_instance )
        --
        local collisions = {
 
-               -- diagram title
-               title   = "Paketkollisionen",
-
-               -- vertical label
-               vlabel  = "Kollisionen/s",
-
                -- diagram data description
                data = {
                        -- data type order
@@ -172,12 +148,6 @@ function rrdargs( graph, plugin, plugin_instance )
        --
        local errors = {
 
-               -- diagram title
-               title   = "TX/RX-Fehler",
-
-               -- vertical label
-               vlabel  = "Kollisionen/s",
-
                -- diagram data description
                data = {
                        -- data type order
index cf1db00b41c6c5bec755b3b46c1465a177bbff5a..a7bf2956cf1ba598d04c5942411c56b24ad7e9cc 100644 (file)
@@ -3,9 +3,6 @@ module("luci.statistics.rrdtool.definitions.ping.ping", package.seeall)
 function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
-               title  = "Pingzeiten",
-               vlabel = "ms",
-
                data = {
                        sources = {
                                ping = { "ping" }
index 715d19c7635d070f55c925dbdb67654136727507..5dd446f3110e12425bed36f656fc6bc6d08079a1 100644 (file)
@@ -3,9 +3,6 @@ module("luci.statistics.rrdtool.definitions.processes.ps_state", package.seeall)
 function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
-               title  = "Prozesse",
-               vlabel = "Anzahl/s",
-
                data = {
                        instances = {
                                ps_state = {
index c944d990d2099bf608866c7afbb740d3828a07db..7f54c109146e3c8e80d07865021fd40292d0354a 100644 (file)
@@ -3,9 +3,6 @@ module("luci.statistics.rrdtool.definitions.tcpconns.tcp_connections", package.s
 function rrdargs( graph, plugin, plugin_instance, dtype )
 
        return {
-               title  = "TCP-Verbindungen auf Port " .. plugin_instance,
-               vlabel = "Anzahl/s",
-
                data = {
                        instances = {
                                tcp_connections = {
@@ -13,12 +10,6 @@ function rrdargs( graph, plugin, plugin_instance, dtype )
                                        "LAST_ACK", "TIME_WAIT", "CLOSING", "CLOSE_WAIT",
                                        "CLOSED", "FIN_WAIT1", "FIN_WAIT2"
                                }
-                       },
-
-                       options = {
-                               tcp_connections = {
-                                       total = true
-                               }
                        }
                }
        }
index 6c68bb2698daf85fddb3d365977afcd8a3aa19ac..7c0888558347c407778b06af4186839de8915750 100644 (file)
@@ -7,12 +7,6 @@ function rrdargs( graph, host, plugin, plugin_instance )
        --
        local snr = {
 
-               -- diagram title
-               title   = "Signal / Noise",
-
-               -- vertical label
-               vlabel  = "dBm",
-
                -- draw this diagram for each data instance
                per_instance = true,
 
@@ -41,12 +35,6 @@ function rrdargs( graph, host, plugin, plugin_instance )
        --
        local quality = {
 
-               -- diagram title
-               title   = "Signalqualitaet",
-
-               -- vertical label
-               vlabel  = "n/5",
-
                -- draw this diagram for each data instance
                per_instance = true,