Sha256: 6117da109a650f1d128903c2668fd6d9ba6fb7263c5a3b78a9a99dd14b056817

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Ezframe
  class Message
    class << self
      def init
        load_yaml_files
      end

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

      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

      def languages
        return @catalog.keys
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ezframe-0.1.1 lib/ezframe/message.rb
ezframe-0.1.0 lib/ezframe/message.rb