diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-05-28 22:34:26 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-05-28 22:34:26 +0000 |
commit | b06638df6e776fc380687b06924a77b03055c00e (patch) | |
tree | 9474d20d6ea68d2bf3911e60b865c306462eac97 /applications/luci-statistics/luasrc/statistics | |
parent | aafa5b786d4692fe65bdc2ac8552976d0a3a3a51 (diff) |
* luci/statistics: implement initial i18n support, added first translations, removed hardcoded strings from models
Diffstat (limited to 'applications/luci-statistics/luasrc/statistics')
10 files changed, 120 insertions, 89 deletions
diff --git a/applications/luci-statistics/luasrc/statistics/i18n.lua b/applications/luci-statistics/luasrc/statistics/i18n.lua new file mode 100644 index 000000000..a31d12667 --- /dev/null +++ b/applications/luci-statistics/luasrc/statistics/i18n.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-statistics/luasrc/statistics/rrdtool.lua index 17ac48a5a..1fe57a225 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua index 5a2ac53ca..bd002e12f 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/cpu/cpu.lua @@ -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 = { diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua index 1b61ad68e..0d812d6ec 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/interface.lua @@ -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, diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua index 455107322..2ab57e862 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/iptables/ipt_packets.lua @@ -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 } } diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua index 47594f0f8..8f32ab3d1 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua @@ -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 diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua index cf1db00b4..a7bf2956c 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/ping/ping.lua @@ -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" } diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua index 715d19c76..5dd446f31 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/processes/ps_state.lua @@ -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 = { diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua index c944d990d..7f54c1091 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/tcpconns/tcp_connections.lua @@ -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 - } } } } diff --git a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua index 6c68bb269..7c0888558 100644 --- a/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua +++ b/applications/luci-statistics/luasrc/statistics/rrdtool/definitions/wireless.lua @@ -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, |