Sha256: 1c44d387b7acb8950e5be4d124bea7e41c1c34d8c40dcf6b55c3c874a4371db1

Contents?: true

Size: 874 Bytes

Versions: 15

Compression:

Stored size: 874 Bytes

Contents

module FastGettext::TranslationRepository
  module DbModels
    class TranslationKey < ActiveRecord::Base
      has_many :translations, :class_name=>'TranslationText'
      accepts_nested_attributes_for :translations, :allow_destroy => true
      
      validates_uniqueness_of :key
      validates_presence_of :key

      def self.translation(key, locale)
        return unless translation_key = find_by_key(key)
        return unless translation_text = translation_key.translations.find_by_locale(locale)
        translation_text.text
      end

      def self.available_locales
        @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
      end

      #this is only for ActiveSupport to get polymorphic_url FastGettext::... namespace free
      def self.model_name
        ActiveSupport::ModelName.new('TranslationKey')
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
grosser-fast_gettext-0.4.10 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.11 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.12 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.13 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.14 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.15 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.16 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.7 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.8 lib/fast_gettext/translation_repository/db_models/translation_key.rb
grosser-fast_gettext-0.4.9 lib/fast_gettext/translation_repository/db_models/translation_key.rb
fast_gettext-0.5.3 lib/fast_gettext/translation_repository/db_models/translation_key.rb
fast_gettext-0.5.2 lib/fast_gettext/translation_repository/db_models/translation_key.rb
fast_gettext-0.5.1 lib/fast_gettext/translation_repository/db_models/translation_key.rb
fast_gettext-0.4.17 lib/fast_gettext/translation_repository/db_models/translation_key.rb
fast_gettext-0.4.16 lib/fast_gettext/translation_repository/db_models/translation_key.rb