* luc/statistics: add file/license headers
[project/luci.git] / applications / luci-statistics / luasrc / statistics / i18n.lua
1 --[[
2
3 Luci statistics - diagram i18n helper
4 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 ]]--
15
16 module("luci.statistics.i18n", package.seeall)
17
18 require("luci.util")
19 require("luci.i18n")
20
21
22 Instance = luci.util.class()
23
24
25 function Instance.__init__( self, graph )
26 self.i18n = luci.i18n
27 self.graph = graph
28
29 -- XXX: compat hack
30 self.i18n.load("statistics.en")
31 end
32
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 "" )
40
41 return str
42 end
43
44 function Instance.title( self, plugin, pinst, dtype, dinst )
45
46 local title = self.i18n.translate(
47 string.format( "stat_dg_title_%s_%s_%s", plugin, pinst, dtype ),
48 self.i18n.translate(
49 string.format( "stat_dg_title_%s_%s", plugin, pinst ),
50 self.i18n.translate(
51 string.format( "stat_dg_title_%s__%s", plugin, dtype ),
52 self.i18n.translate(
53 string.format( "stat_dg_title_%s", plugin ),
54 self.graph:_mkpath( plugin, pinst, dtype )
55 )
56 )
57 )
58 )
59
60 return self:_subst( title, {
61 plugin = plugin,
62 pinst = pinst,
63 dtype = dtype,
64 dinst = dinst
65 } )
66
67 end
68
69 function Instance.label( self, plugin, pinst, dtype, dinst )
70
71 local label = self.i18n.translate(
72 string.format( "stat_dg_label_%s_%s_%s", plugin, pinst, dtype ),
73 self.i18n.translate(
74 string.format( "stat_dg_label_%s_%s", plugin, pinst ),
75 self.i18n.translate(
76 string.format( "stat_dg_label_%s__%s", plugin, dtype ),
77 self.i18n.translate(
78 string.format( "stat_dg_label_%s", plugin ),
79 self.graph:_mkpath( plugin, pinst, dtype )
80 )
81 )
82 )
83 )
84
85 return self:_subst( label, {
86 plugin = plugin,
87 pinst = pinst,
88 dtype = dtype,
89 dinst = dinst
90 } )
91
92 end
93
94 function Instance.ds( self, source )
95
96 local label = self.i18n.translate(
97 string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
98 self.i18n.translate(
99 string.format( "stat_ds_%s_%s", source.type, source.instance ),
100 self.i18n.translate(
101 string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
102 self.i18n.translate(
103 string.format( "stat_ds_%s", source.type ),
104 source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
105 )
106 )
107 )
108 )
109
110 return self:_subst( label, {
111 dtype = source.type,
112 dinst = source.instance,
113 dsrc = source.ds
114 } )
115 end