Sha256: 67f4be00c96170343ff9d7f7aad44f617cda45ac46cbe64f99c899b1b6f29cbe

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

module Lit
  class IncommingLocalization < ActiveRecord::Base
    serialize :translated_value

    ## ASSOCIATIONS
    belongs_to :locale
    belongs_to :localization_key
    belongs_to :localization
    belongs_to :source

    unless defined?(::ActionController::StrongParameters)
      attr_accessible
    end

    ## BEFORE & AFTER
    before_create :set_localization_id


    def get_value
      self.translated_value
    end

    def full_key
      [self.locale_str, self.localization_key_str].join('.')
    end

    def accept
      if self.localization.present?
        self.localization.translated_value = self.translated_value
        self.localization.save
      else
        unless self.locale.present?
          self.locale = Lit::Locale.new
          self.locale.locale = self.locale_str
          self.locale.save
        end
        unless self.localization_key.present?
          self.localization_key = Lit::LocalizationKey.new
          self.localization_key.localization_key = self.localization_key_str
          self.localization_key.save
        end
        unless self.localization.present?
          self.localization = Lit::Localization.new
          self.localization.locale = self.locale
          self.localization.localization_key = self.localization_key
          self.localization.default_value = self.translated_value
          self.localization.save
        end
      end
      self.destroy
    end

    private
      def set_localization_id
        if self.locale.present? and self.localization_key.present?
          self.localization = self.localization_key.localizations.where(:locale_id=>self.locale_id).first
        end
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lit-0.2.1 app/models/lit/incomming_localization.rb
lit-0.2.0 app/models/lit/incomming_localization.rb
lit-0.1.0 app/models/lit/incomming_localization.rb