Sha256: 42d9e57c9e470f378879a8efd9de4ad482eff859c0dbffba5f08aea5e884119c
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
require 'i18n/backend/base' require 'i18n/backend/active_record/translation' require 'i18n/hash' module I18n module Backend class ActiveRecord < Base def reload! end def store_translations(locale, data) data.unwind.each{|key,v| Translation.create(:locale => locale.to_s, :key => key, :value => v) } end def available_locales Translation.find(:all, :select => 'DISTINCT locale').map{|t| t.locale} end protected def lookup(locale, key, scope = [], separator = I18n.default_separator) return unless key separator ||= "." flat_key = (Array(scope) + Array(key)).join( separator ) result = Translation.locale(locale).key(flat_key).find(:first) return result.value if result results = Translation.locale(locale).keys(flat_key, separator) if results.empty? return nil else chop_range = (flat_key.size + separator.size)..-1 return results.inject({}){|hash,r| hash[r.key.slice( chop_range )] = hash[r.value] hash }.wind end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
theoooo-i18n-0.2.0 | lib/i18n/backend/active_record.rb |
theoooo-i18n-0.2.1 | lib/i18n/backend/active_record.rb |
theoooo-i18n-0.2.2 | lib/i18n/backend/active_record.rb |