Sha256: c46b5947ef7dd32c11ea113cc9bb7a44ab5b95e29a6ec417cb2beac06a64cc6b

Contents?: true

Size: 997 Bytes

Versions: 39

Compression:

Stored size: 997 Bytes

Contents

module Lipsiadmin
  module DataBase
    # With this method we can translate define and automatically translate columns for 
    # the current rails locale.
    # 
    # Defining some columns like these:
    # 
    #   m.col :string, :name_it, :name_en, :name_cz
    #   m.col :text, :description_it, :description_en, :description_cz
    #   
    # we can call
    #   
    #   myinstance.name
    # 
    # or
    # 
    #   puts myinstance.description
    #   
    # Lipsiadmin look for name_#{I18n.locale}
    # 
    module TranslateAttributes
      # Define <tt>method missing</tt> to intercept calls to non-localized methods (eg. +name+ instead of +name_cz+)
      def method_missing(method_name, *arguments)
        # puts "Trying to send '#{method_name}_#{I18n.locale}' to #{self.class}" # uncomment for easy debugging in script/console
        return self.send(:"#{method_name}_#{I18n.locale}") if self.respond_to?(:"#{method_name}_#{I18n.locale}")
        super
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
lipsiadmin-5.1.6 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.5 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.4 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.3 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.2 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.1 lib/data_base/translate_attributes.rb
lipsiadmin-5.1.0 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.9 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.8 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.7 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.6 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.5 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.4 lib/data_base/translate_attributes.rb
lipsiadmin-4.1.8 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.0 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.1 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.2 lib/data_base/translate_attributes.rb
lipsiadmin-5.0.3 lib/data_base/translate_attributes.rb
lipsiadmin-3.0 lib/data_base/translate_attributes.rb
lipsiadmin-2.9 lib/data_base/translate_attributes.rb