module Translatable::ActiveRecord::InstanceMethods

Public Instance Methods

other_translations(reload = false) click to toggle source
# File lib/translatable/orm/active_record.rb, line 118
def other_translations(reload = false)
  @other_translations = nil if reload
  @other_translations ||= begin 
    unless association(:current_translation).loaded?
      translations.to_a.reject {|t|t.send(t_locale_column) == ::I18n.locale.to_s}
    else
      translations - [current_translation]
    end
  end
end
set_current_translation(locale = ::I18n.locale)
Alias for: t_set_current
t(locale) click to toggle source
# File lib/translatable/orm/active_record.rb, line 129
def t(locale)
  translations.select { |t| t.send(t_locale_column) == locale.to_s }.first
end
t_set_current(locale = ::I18n.locale) click to toggle source
# File lib/translatable/orm/active_record.rb, line 143
def t_set_current(locale = ::I18n.locale)
  translations.load_target unless translations.loaded?
  association(:current_translation).target = t(locale.to_s)
end
Also aliased as: set_current_translation
with_locale(locale) { || ... } click to toggle source
# File lib/translatable/orm/active_record.rb, line 133
def with_locale(locale, &block)
  begin
    set_current_translation locale.to_sym
    result = block.arity > 0 ? block.call(self) : yield
  ensure
    set_current_translation
  end
  result
end

Protected Instance Methods

t_locale_column() click to toggle source
# File lib/translatable/orm/active_record.rb, line 151
def t_locale_column
  self.class.send(:reflection_locale)
end