class I18n
Constants
- DEFAULT_APPLICATION
- DEFAULT_LOCALE
Attributes
block_parse[RW]
hash[RW]
klasses[RW]
locale[RW]
Public Class Methods
configure(klass = DEFAULT_APPLICATION, locale = DEFAULT_LOCALE)
click to toggle source
# File lib/da_funk/i18n.rb, line 24 def self.configure(klass = DEFAULT_APPLICATION, locale = DEFAULT_LOCALE) @locale = locale unless self.configured? raise I18nError.new("File not found") if (! File.exists?(filepath(klass))) self.parse(klass) raise I18nError.new("Locale not found") unless language end end
configured?()
click to toggle source
# File lib/da_funk/i18n.rb, line 33 def self.configured? @hash && language end
filepath(klass)
click to toggle source
# File lib/da_funk/i18n.rb, line 20 def self.filepath(klass) "./#{klass}/i18n.json" end
get(symbol)
click to toggle source
# File lib/da_funk/i18n.rb, line 70 def self.get(symbol) (language[symbol] || "No Translation").dup end
language()
click to toggle source
# File lib/da_funk/i18n.rb, line 55 def self.language configure unless @hash @hash[@locale] end
merge(hash2)
click to toggle source
# File lib/da_funk/i18n.rb, line 47 def self.merge(hash2) @hash ||= {} hash2.keys.each do |key| @hash[key] ||= {} @hash[key].merge!(hash2[key] || {}) end end
parse(klass)
click to toggle source
# File lib/da_funk/i18n.rb, line 37 def self.parse(klass) @klasses ||= [] if @hash self.merge(JSON.parse(File.read(filepath(klass))).inject({}, &block_parse)) else @hash = JSON.parse(File.read(filepath(klass))).inject({}, &block_parse) end @klasses << klass end
parse_time(value, time)
click to toggle source
# File lib/da_funk/i18n.rb, line 86 def self.parse_time(value, time) value.sub("yy", time.year.to_s). sub("y", time.year.to_s[2..3]). sub("M", rjust(time.month.to_s, 2, "0")). sub("d", rjust(time.day.to_s, 2, "0")). sub("h", rjust(time.hour.to_s, 2, "0")). sub("m", rjust(time.min.to_s, 2, "0")). sub("s", rjust(time.sec.to_s, 2, "0")) end
pt(symbol, options = {})
click to toggle source
# File lib/da_funk/i18n.rb, line 74 def self.pt(symbol, options = {}) if options[:line] || options[:column] line = options[:line] || 0 t(symbol, options).split("\n").each do |message| Device::Display.print_line(message, line, options[:column] || 0) line+=1 end else puts(t(symbol, options)) end end
t(symbol, options = {})
click to toggle source
# File lib/da_funk/i18n.rb, line 60 def self.t(symbol, options = {}) if ! options[:time].nil? parse_time(get(symbol), options[:time]) elsif options[:args] get(symbol) % options[:args] else get(symbol) end end