Class: ActionView::Helpers::Tags::Translator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionview/lib/action_view/helpers/tags/translator.rb |
Class Method Summary
Instance Attribute Summary
- #method_and_value readonly private
- #model readonly private
- #object_name readonly private
- #scope readonly private
Instance Method Summary
- #translate
- #human_attribute_name private
- #i18n_default private
Constructor Details
.new(object, object_name, method_and_value, scope:) ⇒ Translator
# 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 Attribute Details
#method_and_value (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 20
attr_reader :object_name, :method_and_value, :scope, :model
#model (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 20
attr_reader :object_name, :method_and_value, :scope, :model
#object_name (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 20
attr_reader :object_name, :method_and_value, :scope, :model
#scope (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 20
attr_reader :object_name, :method_and_value, :scope, :model
Instance Method Details
#human_attribute_name (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 31
def human_attribute_name if model && model.class.respond_to?(:human_attribute_name) model.class.human_attribute_name(method_and_value) end end
#i18n_default (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/translator.rb', line 22
def i18n_default if model key = model.model_name.i18n_key ["#{key}.#{method_and_value}".to_sym, ""] else "" end end
#translate
[ GitHub ]# 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