Browse files

Allow :t as a shorthand for :translate

  • Loading branch information...
1 parent d502ecf commit a7c3d520727eeb6a23007b8bb4edfc6b44e8e3f8 @haines committed Feb 6, 2013
Showing with 20 additions and 1 deletion.
  1. +2 −1 lib/simple_form/inputs/collection_input.rb
  2. +18 −0 test/inputs/collection_select_input_test.rb
View
3 lib/simple_form/inputs/collection_input.rb
@@ -105,7 +105,8 @@ def translate_collection
def translate_option(options, key)
return unless options[key].is_a? Symbol
- options[key] = if options[key] == :translate
+ options[key] = case options[key]
+ when :translate, :t
translate(key, true)
else
I18n.t(options[key], scope: :"simple_form.#{key}")
View
18 test/inputs/collection_select_input_test.rb
@@ -105,6 +105,15 @@ class CollectionSelectInputTest < ActionView::TestCase
end
end
+ test 'input should translate include blank when set to :t' do
+ store_translations(:en, :simple_form => { :include_blank => { :user => {
+ :age => 'Rather not say'
+ } } } ) do
+ with_input_for @user, :age, :select, :collection => 18..30, :include_blank => :t
+ assert_select 'select option[value=]', 'Rather not say'
+ end
+ end
+
test 'input should translate include blank with a particular key' do
store_translations(:en, :simple_form => { :include_blank => {
:age => 'Rather not say',
@@ -175,6 +184,15 @@ class CollectionSelectInputTest < ActionView::TestCase
end
end
+ test 'input should translate prompt when set to :t' do
+ store_translations(:en, :simple_form => { :prompt => { :user => {
+ :age => 'Select age:'
+ } } } ) do
+ with_input_for @user, :age, :select, :collection => 18..30, :prompt => :t
+ assert_select 'select option[value=]', 'Select age:'
+ end
+ end
+
test 'input should translate prompt with a particular key' do
store_translations(:en, :simple_form => { :prompt => {
:age => 'Select age:',

0 comments on commit a7c3d52

Please sign in to comment.