Module: Translatable::ActiveRecord::InstanceMethods
- Defined in:
- lib/translatable/orm/active_record.rb
Instance Method Summary collapse
- #other_translations(reload = false) ⇒ Object
- #t(locale) ⇒ Object
- #t_set_current(locale = ::I18n.locale) ⇒ Object (also: #set_current_translation)
- #with_locale(locale, &block) ⇒ Object
Instance Method Details
#other_translations(reload = false) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# 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 |
#t(locale) ⇒ Object
129 130 131 |
# 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) ⇒ Object Also known as: set_current_translation
143 144 145 146 |
# 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 |
#with_locale(locale, &block) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# 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 |