Class: Ezframe::Message

Inherits:
Object show all
Defined in:
lib/ezframe/message.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



41
42
43
# File 'lib/ezframe/message.rb', line 41

def [](key)
  return get(key)
end

.get(key, lang = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/ezframe/message.rb', line 34

def get(key, lang = nil)
  lang = languages[0] unless lang
  messages = @catalog[lang]
  return messages[key.to_sym] if messages
  return nil
end

.initObject



4
5
6
# File 'lib/ezframe/message.rb', line 4

def init
  load_yaml_files
end

.languagesObject



30
31
32
# File 'lib/ezframe/message.rb', line 30

def languages
  return @catalog.keys
end

.load_one_file(file) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ezframe/message.rb', line 17

def load_one_file(file)
  begin
    yaml = YAML.load_file(file)
  rescue
    mylog("YAML load error: #{file}")
    return 
  end
  if /([a-z]{2})\.yml$/ =~ file
    lang = $1
    @catalog[lang.to_sym] = yaml.recursively_symbolize_keys
  end
end

.load_yaml_files(dir = "./message") ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/ezframe/message.rb', line 8

def load_yaml_files(dir = "./message")
  unless @catalog
    @catalog = {}
    Dir["#{dir}/*.yml"].each do |file|
      load_one_file(file)
    end
  end
end