* luci/statistics: replace load() with loadc() since german translation is now available
[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         self.i18n.loadc("statistics")
30 end
31
32 function Instance._subst( self, str, val )
33         str = str:gsub( "%%H",  self.graph.opts.host or "" )
34         str = str:gsub( "%%pn", val.plugin or "" )
35         str = str:gsub( "%%pi", val.pinst  or "" )
36         str = str:gsub( "%%dt", val.dtype  or "" )
37         str = str:gsub( "%%di", val.dinst  or "" )
38         str = str:gsub( "%%ds", val.dsrc   or "" )
39
40         return str
41 end
42
43 function Instance.title( self, plugin, pinst, dtype, dinst )
44
45         local title = self.i18n.translate(
46                 string.format( "stat_dg_title_%s_%s_%s", plugin, pinst, dtype ),
47                 self.i18n.translate(
48                         string.format( "stat_dg_title_%s_%s", plugin, pinst ),
49                         self.i18n.translate(
50                                 string.format( "stat_dg_title_%s__%s", plugin, dtype ),
51                                 self.i18n.translate(
52                                         string.format( "stat_dg_title_%s", plugin ),
53                                         self.graph:_mkpath( plugin, pinst, dtype )
54                                 )
55                         )
56                 )
57         )
58
59         return self:_subst( title, { 
60                 plugin = plugin,
61                 pinst  = pinst,
62                 dtype  = dtype,
63                 dinst  = dinst
64         } )
65
66 end
67
68 function Instance.label( self, plugin, pinst, dtype, dinst )
69
70         local label = self.i18n.translate(
71                 string.format( "stat_dg_label_%s_%s_%s", plugin, pinst, dtype ),
72                 self.i18n.translate(
73                         string.format( "stat_dg_label_%s_%s", plugin, pinst ),
74                         self.i18n.translate(
75                                 string.format( "stat_dg_label_%s__%s", plugin, dtype ),
76                                 self.i18n.translate(
77                                         string.format( "stat_dg_label_%s", plugin ),
78                                         self.graph:_mkpath( plugin, pinst, dtype )
79                                 )
80                         )
81                 )
82         )
83
84         return self:_subst( label, { 
85                 plugin = plugin,
86                 pinst  = pinst,
87                 dtype  = dtype,
88                 dinst  = dinst
89         } )
90
91 end
92
93 function Instance.ds( self, source )
94
95         local label = self.i18n.translate(
96                 string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
97                 self.i18n.translate(
98                         string.format( "stat_ds_%s_%s", source.type, source.instance ),
99                         self.i18n.translate(
100                                 string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
101                                 self.i18n.translate(
102                                         string.format( "stat_ds_%s", source.type ),
103                                         source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
104                                 )
105                         )
106                 )
107         )
108
109         return self:_subst( label, { 
110                 dtype = source.type,
111                 dinst = source.instance,
112                 dsrc  = source.ds
113         } )
114 end