Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make sure #localize does not alter the stored format string

  • Loading branch information...
commit 75a407143fd7a3e07d7b4e4d1735dbb9343bdc17 1 parent 66e0eb7
@svenfuchs svenfuchs authored
Showing with 10 additions and 2 deletions.
  1. +2 −1  lib/i18n/backend/simple.rb
  2. +8 −1 test/api/localization/date.rb
View
3  lib/i18n/backend/simple.rb
@@ -49,6 +49,7 @@ def localize(locale, object, format = :default, options={})
end
format = resolve(locale, object, format, options.merge(:raise => true))
+ format = format.dup if format
# TODO check which format strings are present, then bulk translate them, then replace them
format.gsub!(/%a/, translate(locale, :"date.abbr_day_names", :format => format)[object.wday]) if format.include?('%a')
@@ -230,4 +231,4 @@ def flatten_once(array)
end
end
end
-end
+end
View
9 test/api/localization/date.rb
@@ -41,6 +41,13 @@ def test_localize_given_a_format_specified_as_a_proc_with_additional_options
assert_equal '1ter März 2008 (MEZ)', I18n.backend.localize('de', date, :long_ordinalized, :timezone => 'MEZ')
end
+ def test_localize_does_not_alter_the_stored_format_string
+ first_of_jan = I18n.backend.localize(:de, ::Date.parse('2009-01-01'), :long)
+ first_of_oct = I18n.backend.localize(:de, ::Date.parse('2009-10-01'), :long)
+ assert_equal '01. Januar 2009', first_of_jan
+ assert_equal '01. Oktober 2009', first_of_oct
+ end
+
def test_localize_given_no_format_it_does_not_fail
assert_nothing_raised{ I18n.backend.localize 'de', date }
end
@@ -60,4 +67,4 @@ def test_localize_object_raises_argument_error
end
end
end
-end
+end

0 comments on commit 75a4071

Please sign in to comment.
Something went wrong with that request. Please try again.