class Tcl::Msgcat::Renderer
Attributes
lines[R]
msgs[R]
Public Class Methods
new(msgs, lang=nil)
click to toggle source
# File lib/tcl/msgcat/renderer.rb, line 5 def initialize(msgs, lang=nil) @msgs = msgs @lang = lang @lines = [] end
Public Instance Methods
render()
click to toggle source
# File lib/tcl/msgcat/renderer.rb, line 11 def render @lines << "package require mchelper" if (@lang.nil? or @lang.downcase == "root") @lines << "msg_lang {}" else @lines << "msg_lang #{@lang}" end @lines << "" _render(@msgs) self end
to_s()
click to toggle source
# File lib/tcl/msgcat/renderer.rb, line 26 def to_s @lines.join("\n") end
Private Instance Methods
_render(msgs, level=0)
click to toggle source
A recursive function that calls itself when the value of a key is a hash so it can iterate through every dimension of the hash to get at the translation labels and strings
# File lib/tcl/msgcat/renderer.rb, line 36 def _render(msgs, level=0) msgs.each do |key, value| if value.is_a? Hash @lines << "" @lines << "msgs #{key} {".rpad(" ", level) level+=1 _render(value, level) # render any child hashes or translation labels/strings level-=1 @lines << "}".rpad(" ", level) @lines << "" end if value.is_a? String @lines << "m #{key} \"#{value}\"".rpad(" ", level) end end end