Sha256: b567d62960aba72471e94686556e3872b8b26071cb7c5891db4317e74e80b07f
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require 'active_record' module I18n module Backend class Releaf class Translation < ::ActiveRecord::Base self.table_name = "releaf_translations" validates_presence_of :group_id, :key validates_uniqueness_of :key, :scope => :group_id belongs_to :translation_group, :foreign_key => :group_id has_many :translation_data, :dependent => :destroy, :class_name => 'Releaf::TranslationData' attr_accessible \ :group_id, :key scope :joined, select('releaf_translations.*, releaf_translation_data.lang as "lang", releaf_translation_data.localization as "localization", releaf_translation_groups.scope as "scope"'). joins(:translation_data, :translation_group) scope :get_translated, joined.where('releaf_translation_data.lang IS NOT NULL'); scope :lookup, lambda { |locale, keys, scope| joined.where('releaf_translation_groups.scope = :scope AND releaf_translation_data.lang = :locale AND releaf_translations.key in (:keys)', :keys => keys, :locale => locale, :scope => scope) } scope :filter, lambda{ |params| where( 'releaf_translations.key LIKE ?', "%#{params[:search]}%" ) unless params[:search].blank? } after_commit :reload_cache def locales values = {} Settings.i18n_locales.each do |locale| values[locale] = nil end translation_data.find_each do |value| values[value.lang] = value.localization if values.has_key? value.lang end values end def plain_key key.gsub(translation_group.scope + '.', '') end private def reload_cache Settings.i18n_updated_at = Time.now I18n.backend.reload_cache end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
releaf-0.1.2 | lib/i18n/backend/releaf/translation.rb |