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

Inherits:
Object
  • Object
show all
Defined in:
actionview/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.



7
8
9
10
11
12
# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 7

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



14
15
16
17
# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 14

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