1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.statistics.i18n", package.seeall)
10 Instance = luci.util.class()
13 function Instance.__init__( self, graph )
18 function Instance._subst( self, str, val )
19 str = str:gsub( "%%H", self.graph.opts.host or "" )
20 str = str:gsub( "%%pn", val.plugin or "" )
21 str = str:gsub( "%%pi", val.pinst or "" )
22 str = str:gsub( "%%dt", val.dtype or "" )
23 str = str:gsub( "%%di", val.dinst or "" )
24 str = str:gsub( "%%ds", val.dsrc or "" )
29 function Instance._translate( self, key, alt )
30 local val = self.i18n.string(key)
38 function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
40 local title = user_title or
41 "p=%s/pi=%s/dt=%s/di=%s" % {
43 (pinst and #pinst > 0) and pinst or "(nil)",
44 (dtype and #dtype > 0) and dtype or "(nil)",
45 (dinst and #dinst > 0) and dinst or "(nil)"
48 return self:_subst( title, {
57 function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
59 local label = user_label or
61 (dtype and #dtype > 0) and dtype or "(nil)",
62 (dinst and #dinst > 0) and dinst or "(nil)"
65 return self:_subst( label, {
74 function Instance.ds( self, source )
76 local label = source.title or self:_translate(
77 string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
79 string.format( "stat_ds_%s_%s", source.type, source.instance ),
81 string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
83 string.format( "stat_ds_%s", source.type ),
84 source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
90 return self:_subst( label, {
92 dinst = source.instance,