Use kwags to make the argument meaning explicit

上级 d80996ea
......@@ -17,7 +17,7 @@ def translation
method_and_value = @tag_value.present? ? "#{@method_name}.#{@tag_value}" : @method_name
content ||= Translator
.new(object, @object_name, method_and_value, "helpers.label")
.new(object, @object_name, method_and_value, scope: "helpers.label")
.call
content ||= @method_name.humanize
......
......@@ -10,7 +10,7 @@ def initialize(*)
method_and_value = tag_value.is_a?(TrueClass) ? @method_name : "#{@method_name}.#{tag_value}"
placeholder ||= Tags::Translator
.new(object, @object_name, method_and_value, "helpers.placeholder")
.new(object, @object_name, method_and_value, scope: "helpers.placeholder")
.call
placeholder ||= @method_name.humanize
@options[:placeholder] = placeholder
......
......@@ -2,21 +2,21 @@ module ActionView
module Helpers
module Tags # :nodoc:
class Translator # :nodoc:
def initialize(object, object_name, method_and_value, i18n_scope)
def initialize(object, object_name, method_and_value, scope:)
@object_name = object_name.gsub(/\[(.*)_attributes\]\[\d+\]/, '.\1')
@method_and_value = method_and_value
@i18n_scope = i18n_scope
@scope = scope
@model = object.respond_to?(:to_model) ? object.to_model : object
end
def call
translated_attribute = I18n.t("#{object_name}.#{method_and_value}", default: i18n_default, scope: i18n_scope).presence
translated_attribute = I18n.t("#{object_name}.#{method_and_value}", default: i18n_default, scope: scope).presence
translated_attribute || human_attribute_name
end
private
attr_reader :object_name, :method_and_value, :i18n_scope, :model
attr_reader :object_name, :method_and_value, :scope, :model
def i18n_default
if model
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册