diff --git a/lib/simple_form.rb b/lib/simple_form.rb index f007ccab..53d44c6a 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -99,10 +99,10 @@ module SimpleForm mattr_accessor :default_input_size @@default_input_size = 50 - # When off, do not use translations in hint, labels and placeholders. - # It is a small performance improvement if you are not using such features. - mattr_accessor :translate - @@translate = true + # When off, do not use translations in labels. Disabling translation in + # hints and placeholders can be done manually in the wrapper API. + mattr_accessor :translate_labels + @@translate_labels = true # Automatically discover new inputs in Rails' autoload path. mattr_accessor :inputs_discovery @@ -165,7 +165,17 @@ module SimpleForm @@deprecated = false 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 # Default way to setup SimpleForm. Run rails generate simple_form:install diff --git a/lib/simple_form/components/disabled.rb b/lib/simple_form/components/disabled.rb deleted file mode 100644 index 35ca288e..00000000 --- a/lib/simple_form/components/disabled.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/simple_form/components/hints.rb b/lib/simple_form/components/hints.rb index 6f042224..931ab675 100644 --- a/lib/simple_form/components/hints.rb +++ b/lib/simple_form/components/hints.rb @@ -1,8 +1,13 @@ module SimpleForm module Components + # Needs to be enabled in order to do automatic lookups. module Hints def hint - (options.delete(:hint) || translate(:hints)).presence + if options[:hint] == true + translate(:hints).presence + else + options[:hint] + end end end end diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index adab0e0a..f71b1f8e 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -56,7 +56,7 @@ module SimpleForm # First check labels translation and then human attribute name. 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) else attribute_name.to_s.humanize diff --git a/lib/simple_form/components/maxlength.rb b/lib/simple_form/components/maxlength.rb index eaa496a2..488a42b9 100644 --- a/lib/simple_form/components/maxlength.rb +++ b/lib/simple_form/components/maxlength.rb @@ -1,5 +1,6 @@ module SimpleForm module Components + # Needs to be enabled in order to do automatic lookups. module Maxlength def maxlength input_html_options[:maxlength] ||= maximum_length_from_validation || limit diff --git a/lib/simple_form/components/pattern.rb b/lib/simple_form/components/pattern.rb index 85fb6a1b..bff46c1c 100644 --- a/lib/simple_form/components/pattern.rb +++ b/lib/simple_form/components/pattern.rb @@ -1,5 +1,6 @@ module SimpleForm module Components + # Needs to be enabled in order to do automatic lookups. module Pattern def pattern input_html_options[:pattern] ||= pattern_source diff --git a/lib/simple_form/components/placeholders.rb b/lib/simple_form/components/placeholders.rb index 93fe2232..f4200499 100644 --- a/lib/simple_form/components/placeholders.rb +++ b/lib/simple_form/components/placeholders.rb @@ -1,5 +1,6 @@ module SimpleForm module Components + # Needs to be enabled in order to do automatic lookups. module Placeholders def placeholder input_html_options[:placeholder] ||= placeholder_text diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 0fe94463..a986996c 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -39,6 +39,9 @@ module SimpleForm self.default_options = options end + # Always enabled. + enable :hint + # Usually disabled, needs to be enabled explicitly passing true as option. disable :maxlength, :placeholder, :pattern @@ -126,8 +129,6 @@ module SimpleForm # # Take a look at our locale example file. def translate(namespace, default='') - return nil unless SimpleForm.translate - model_names = lookup_model_names.dup lookups = [] diff --git a/test/components/label_test.rb b/test/components/label_test.rb index 36bde220..c7d335f1 100644 --- a/test/components/label_test.rb +++ b/test/components/label_test.rb @@ -80,7 +80,7 @@ class IsolatedLabelTest < ActionView::TestCase end 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 with_label_for @user, :age, :integer assert_select 'label[for=user_age]', /Age/