Class: ActionView::Helpers::Tags::Translator
- Inherits:
-
Object
- Object
- ActionView::Helpers::Tags::Translator
- Defined in:
- lib/action_view/helpers/tags/translator.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(object, object_name, method_and_value, scope:) ⇒ Translator
constructor
A new instance of Translator.
- #translate ⇒ Object
Constructor Details
#initialize(object, object_name, method_and_value, scope:) ⇒ Translator
Returns a new instance of Translator.
7 8 9 10 11 12 |
# File '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
#translate ⇒ Object
14 15 16 17 |
# File '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 |