Merge pull request #917 from aa65535/master
[project/luci.git] / applications / luci-app-statistics / luasrc / statistics / i18n.lua
1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.statistics.i18n", package.seeall)
5
6 require("luci.util")
7 require("luci.i18n")
8
9
10 Instance = luci.util.class()
11
12
13 function Instance.__init__( self, graph )
14         self.i18n  = luci.i18n
15         self.graph = graph
16 end
17
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 "" )
25
26         return str
27 end
28
29 function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
30
31         local title = user_title or
32                 "p=%s/pi=%s/dt=%s/di=%s" % {
33                         plugin,
34                         (pinst and #pinst > 0) and pinst or "(nil)",
35                         (dtype and #dtype > 0) and dtype or "(nil)",
36                         (dinst and #dinst > 0) and dinst or "(nil)"
37                 }
38
39         return self:_subst( title, {
40                 plugin = plugin,
41                 pinst  = pinst,
42                 dtype  = dtype,
43                 dinst  = dinst
44         } )
45
46 end
47
48 function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
49
50         local label = user_label or
51                 "dt=%s/di=%s" % {
52                         (dtype and #dtype > 0) and dtype or "(nil)",
53                         (dinst and #dinst > 0) and dinst or "(nil)"
54                 }
55
56         return self:_subst( label, {
57                 plugin = plugin,
58                 pinst  = pinst,
59                 dtype  = dtype,
60                 dinst  = dinst
61         } )
62
63 end
64
65 function Instance.ds( self, source )
66
67         local label = source.title or
68                 "dt=%s/di=%s/ds=%s" % {
69                         (source.type     and #source.type     > 0) and source.type     or "(nil)",
70                         (source.instance and #source.instance > 0) and source.instance or "(nil)",
71                         (source.ds       and #source.ds       > 0) and source.ds       or "(nil)"
72                 }
73
74         return self:_subst( label, {
75                 dtype = source.type,
76                 dinst = source.instance,
77                 dsrc  = source.ds
78         } ):gsub(":", "\\:")
79
80 end