Sha256: 25c031c64f5dd5e56f445602060a6173266c839bb558907f3467ffd5e3225eb4
Contents?: true
Size: 815 Bytes
Versions: 2
Compression:
Stored size: 815 Bytes
Contents
class Translation < String attr_accessor :keys def initialize(*args) super @keys = {} @keys["default"] = "en" end def []=(lang, text) @keys[lang.to_s] = text end def [](lang) @keys[lang.to_s] end def languages langs = @keys.keys langs.delete("default") langs end def default_language=(lang) @keys["default"] = lang self.replace(@keys[lang.to_s]) end def self.build(keys, default = "en") tr = self.new tr.keys = keys tr.default_language = default tr end def self.set(value) return value.keys if value.kind_of?(self) @keys end def self.get(value) return value if value.kind_of?(self) result = self.new result.keys = value result.default_language = value["default"] || "en" result end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid_ext-0.6.2 | lib/mongoid_ext/types/translation.rb |
mongoid_ext-0.6.1 | lib/mongoid_ext/types/translation.rb |