Sha256: a9dd77e42afa8994eee9171c068b9c360279ccaa8d8042857226096323b889bf

Contents?: true

Size: 474 Bytes

Versions: 1

Compression:

Stored size: 474 Bytes

Contents

# encoding: utf-8

class Localization < ActiveRecord::Base
  belongs_to :localizable, polymorphic: true, optional: true

  class << self
    def locales
      order("locale ASC").pluck(Arel.sql("DISTINCT locale"))
    end

    def names
      order("name ASC").pluck(Arel.sql("DISTINCT name"))
    end
  end

  def to_s
    value || ""
  end

  delegate :empty?, to: :to_s

  def translate(locale)
    localizable.localizations.find_by(name: name, locale: locale)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localizable_model-0.6.2 app/models/localization.rb