class MiniI18n
Attributes
locale[R]
Public Class Methods
new()
click to toggle source
# File lib/mini-i18n.rb, line 4 def initialize @index = {} @locale = 'en' end
Public Instance Methods
load_yml(path)
click to toggle source
# File lib/mini-i18n.rb, line 13 def load_yml(path) @index = YAML.load_file(path) end
locale=(locale)
click to toggle source
# File lib/mini-i18n.rb, line 9 def locale=(locale) @locale = locale.to_s end
translate(key)
click to toggle source
# File lib/mini-i18n.rb, line 17 def translate(key) keys = [locale] + key.split('.') translation = keys.reduce(@index) {|hash, key| hash.fetch(key.to_s)} translation.to_s end