3 Luci statistics - diagram i18n helper
4 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.statistics.i18n", package.seeall)
22 Instance = luci.util.class()
25 function Instance.__init__( self, graph )
29 self.i18n.loadc("rrdtool")
30 self.i18n.loadc("statistics")
33 function Instance._subst( self, str, val )
34 str = str:gsub( "%%H", self.graph.opts.host or "" )
35 str = str:gsub( "%%pn", val.plugin or "" )
36 str = str:gsub( "%%pi", val.pinst or "" )
37 str = str:gsub( "%%dt", val.dtype or "" )
38 str = str:gsub( "%%di", val.dinst or "" )
39 str = str:gsub( "%%ds", val.dsrc or "" )
44 function Instance._translate( self, key, alt )
45 local val = self.i18n.string(key)
53 function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
55 local title = user_title or
56 "p=%s/pi=%s/dt=%s/di=%s" % {
58 (pinst and #pinst > 0) and pinst or "(nil)",
59 (dtype and #dtype > 0) and dtype or "(nil)",
60 (dinst and #dinst > 0) and dinst or "(nil)"
63 return self:_subst( title, {
72 function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
74 local label = user_label or
76 (dtype and #dtype > 0) and dtype or "(nil)",
77 (dinst and #dinst > 0) and dinst or "(nil)"
80 return self:_subst( label, {
89 function Instance.ds( self, source )
91 local label = source.title or self:_translate(
92 string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
94 string.format( "stat_ds_%s_%s", source.type, source.instance ),
96 string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
98 string.format( "stat_ds_%s", source.type ),
99 source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
105 return self:_subst( label, {
107 dinst = source.instance,