Class: ActionView::Helpers::Tags::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/helpers/tags/translator.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(object, object_name, method_and_value, scope) ⇒ Translator

Returns a new instance of Translator.



5
6
7
8
9
10
# File 'lib/action_view/helpers/tags/translator.rb', line 5

def initialize(object, object_name, method_and_value, scope)
  @object_name = object_name.gsub(/\[(.*)_attributes\]\[\d+\]/, '.\1')
  @method_and_value = method_and_value
  @scope = scope
  @model = object.respond_to?(:to_model) ? object.to_model : nil
end

Instance Method Details

#translateObject



12
13
14
15
# File 'lib/action_view/helpers/tags/translator.rb', line 12

def translate
  translated_attribute = I18n.t("#{object_name}.#{method_and_value}", default: i18n_default, scope: scope).presence
  translated_attribute || human_attribute_name
end