1
0

i18n.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.statistics.i18n", package.seeall)
  4. require("luci.util")
  5. require("luci.i18n")
  6. Instance = luci.util.class()
  7. function Instance.__init__( self, graph )
  8. self.i18n = luci.i18n
  9. self.graph = graph
  10. end
  11. function Instance._subst( self, str, val )
  12. str = str:gsub( "%%H", self.graph.opts.host or "" )
  13. str = str:gsub( "%%pn", val.plugin or "" )
  14. str = str:gsub( "%%pi", val.pinst or "" )
  15. str = str:gsub( "%%dt", val.dtype or "" )
  16. str = str:gsub( "%%di", val.dinst or "" )
  17. str = str:gsub( "%%ds", val.dsrc or "" )
  18. return str
  19. end
  20. function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
  21. local title = user_title or
  22. "p=%s/pi=%s/dt=%s/di=%s" % {
  23. plugin,
  24. (pinst and #pinst > 0) and pinst or "(nil)",
  25. (dtype and #dtype > 0) and dtype or "(nil)",
  26. (dinst and #dinst > 0) and dinst or "(nil)"
  27. }
  28. return self:_subst( title, {
  29. plugin = plugin,
  30. pinst = pinst,
  31. dtype = dtype,
  32. dinst = dinst
  33. } )
  34. end
  35. function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
  36. local label = user_label or
  37. "dt=%s/di=%s" % {
  38. (dtype and #dtype > 0) and dtype or "(nil)",
  39. (dinst and #dinst > 0) and dinst or "(nil)"
  40. }
  41. return self:_subst( label, {
  42. plugin = plugin,
  43. pinst = pinst,
  44. dtype = dtype,
  45. dinst = dinst
  46. } )
  47. end
  48. function Instance.ds( self, source )
  49. local label = source.title or
  50. "dt=%s/di=%s/ds=%s" % {
  51. (source.type and #source.type > 0) and source.type or "(nil)",
  52. (source.instance and #source.instance > 0) and source.instance or "(nil)",
  53. (source.ds and #source.ds > 0) and source.ds or "(nil)"
  54. }
  55. return self:_subst( label, {
  56. dtype = source.type,
  57. dinst = source.instance,
  58. dsrc = source.ds
  59. } ):gsub(":", "\\:")
  60. end