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 )
30 function Instance._subst( self, str, val )
31 str = str:gsub( "%%H", self.graph.opts.host or "" )
32 str = str:gsub( "%%pn", val.plugin or "" )
33 str = str:gsub( "%%pi", val.pinst or "" )
34 str = str:gsub( "%%dt", val.dtype or "" )
35 str = str:gsub( "%%di", val.dinst or "" )
36 str = str:gsub( "%%ds", val.dsrc or "" )
41 function Instance._translate( self, key, alt )
42 local val = self.i18n.string(key)
50 function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
52 local title = user_title or
53 "p=%s/pi=%s/dt=%s/di=%s" % {
55 (pinst and #pinst > 0) and pinst or "(nil)",
56 (dtype and #dtype > 0) and dtype or "(nil)",
57 (dinst and #dinst > 0) and dinst or "(nil)"
60 return self:_subst( title, {
69 function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
71 local label = user_label or
73 (dtype and #dtype > 0) and dtype or "(nil)",
74 (dinst and #dinst > 0) and dinst or "(nil)"
77 return self:_subst( label, {
86 function Instance.ds( self, source )
88 local label = source.title or self:_translate(
89 string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
91 string.format( "stat_ds_%s_%s", source.type, source.instance ),
93 string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
95 string.format( "stat_ds_%s", source.type ),
96 source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
102 return self:_subst( label, {
104 dinst = source.instance,