Deprecate translate in favor of disabling the automatic lookup in hints and placeholders.
This commit is contained in:
parent
94dab68cd7
commit
50b24b5cbe
|
@ -99,10 +99,10 @@ module SimpleForm
|
||||||
mattr_accessor :default_input_size
|
mattr_accessor :default_input_size
|
||||||
@@default_input_size = 50
|
@@default_input_size = 50
|
||||||
|
|
||||||
# When off, do not use translations in hint, labels and placeholders.
|
# When off, do not use translations in labels. Disabling translation in
|
||||||
# It is a small performance improvement if you are not using such features.
|
# hints and placeholders can be done manually in the wrapper API.
|
||||||
mattr_accessor :translate
|
mattr_accessor :translate_labels
|
||||||
@@translate = true
|
@@translate_labels = true
|
||||||
|
|
||||||
# Automatically discover new inputs in Rails' autoload path.
|
# Automatically discover new inputs in Rails' autoload path.
|
||||||
mattr_accessor :inputs_discovery
|
mattr_accessor :inputs_discovery
|
||||||
|
@ -165,7 +165,17 @@ module SimpleForm
|
||||||
@@deprecated = false
|
@@deprecated = false
|
||||||
|
|
||||||
DEPRECATED.each do |method|
|
DEPRECATED.each do |method|
|
||||||
class_eval "def #{method}; @@deprecated = true; end"
|
class_eval "def self.#{method}; @@deprecated = true; end"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.translate=(value)
|
||||||
|
ActiveSupport::Deprecation.warn "SimpleForm.translate= is disabled in favor of translate_labels="
|
||||||
|
self.translate_labels = value
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.translate
|
||||||
|
ActiveSupport::Deprecation.warn "SimpleForm.translate is disabled in favor of translate_labels"
|
||||||
|
self.translate_labels
|
||||||
end
|
end
|
||||||
|
|
||||||
# Default way to setup SimpleForm. Run rails generate simple_form:install
|
# Default way to setup SimpleForm. Run rails generate simple_form:install
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
module SimpleForm
|
|
||||||
module Components
|
|
||||||
module Disabled
|
|
||||||
def disabled
|
|
||||||
if has_disabled?
|
|
||||||
input_html_classes << 'disabled'
|
|
||||||
input_html_options[:disabled] = true
|
|
||||||
end
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_disabled?
|
|
||||||
options[:disabled] == true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,8 +1,13 @@
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
module Components
|
module Components
|
||||||
|
# Needs to be enabled in order to do automatic lookups.
|
||||||
module Hints
|
module Hints
|
||||||
def hint
|
def hint
|
||||||
(options.delete(:hint) || translate(:hints)).presence
|
if options[:hint] == true
|
||||||
|
translate(:hints).presence
|
||||||
|
else
|
||||||
|
options[:hint]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,7 @@ module SimpleForm
|
||||||
|
|
||||||
# First check labels translation and then human attribute name.
|
# First check labels translation and then human attribute name.
|
||||||
def label_translation #:nodoc:
|
def label_translation #:nodoc:
|
||||||
translate(:labels) || if object.class.respond_to?(:human_attribute_name)
|
(SimpleForm.translate_labels && translate(:labels)) || if object.class.respond_to?(:human_attribute_name)
|
||||||
object.class.human_attribute_name(reflection_or_attribute_name.to_s)
|
object.class.human_attribute_name(reflection_or_attribute_name.to_s)
|
||||||
else
|
else
|
||||||
attribute_name.to_s.humanize
|
attribute_name.to_s.humanize
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
module Components
|
module Components
|
||||||
|
# Needs to be enabled in order to do automatic lookups.
|
||||||
module Maxlength
|
module Maxlength
|
||||||
def maxlength
|
def maxlength
|
||||||
input_html_options[:maxlength] ||= maximum_length_from_validation || limit
|
input_html_options[:maxlength] ||= maximum_length_from_validation || limit
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
module Components
|
module Components
|
||||||
|
# Needs to be enabled in order to do automatic lookups.
|
||||||
module Pattern
|
module Pattern
|
||||||
def pattern
|
def pattern
|
||||||
input_html_options[:pattern] ||= pattern_source
|
input_html_options[:pattern] ||= pattern_source
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
module Components
|
module Components
|
||||||
|
# Needs to be enabled in order to do automatic lookups.
|
||||||
module Placeholders
|
module Placeholders
|
||||||
def placeholder
|
def placeholder
|
||||||
input_html_options[:placeholder] ||= placeholder_text
|
input_html_options[:placeholder] ||= placeholder_text
|
||||||
|
|
|
@ -39,6 +39,9 @@ module SimpleForm
|
||||||
self.default_options = options
|
self.default_options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Always enabled.
|
||||||
|
enable :hint
|
||||||
|
|
||||||
# Usually disabled, needs to be enabled explicitly passing true as option.
|
# Usually disabled, needs to be enabled explicitly passing true as option.
|
||||||
disable :maxlength, :placeholder, :pattern
|
disable :maxlength, :placeholder, :pattern
|
||||||
|
|
||||||
|
@ -126,8 +129,6 @@ module SimpleForm
|
||||||
#
|
#
|
||||||
# Take a look at our locale example file.
|
# Take a look at our locale example file.
|
||||||
def translate(namespace, default='')
|
def translate(namespace, default='')
|
||||||
return nil unless SimpleForm.translate
|
|
||||||
|
|
||||||
model_names = lookup_model_names.dup
|
model_names = lookup_model_names.dup
|
||||||
lookups = []
|
lookups = []
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should not use i18n label if translate is false' do
|
test 'input should not use i18n label if translate is false' do
|
||||||
swap SimpleForm, :translate => false do
|
swap SimpleForm, :translate_labels => false do
|
||||||
store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
|
store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
|
||||||
with_label_for @user, :age, :integer
|
with_label_for @user, :age, :integer
|
||||||
assert_select 'label[for=user_age]', /Age/
|
assert_select 'label[for=user_age]', /Age/
|
||||||
|
|
Loading…
Reference in New Issue