i18n 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of i18n might be problematic. Click here for more details.

Files changed (58) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG.textile +12 -3
  3. data/README.textile +4 -17
  4. data/lib/i18n.rb +5 -9
  5. data/lib/i18n/backend.rb +0 -1
  6. data/lib/i18n/backend/base.rb +4 -32
  7. data/lib/i18n/backend/gettext.rb +3 -3
  8. data/lib/i18n/backend/interpolation_compiler.rb +1 -1
  9. data/lib/i18n/backend/metadata.rb +1 -1
  10. data/lib/i18n/config.rb +1 -1
  11. data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
  12. data/lib/i18n/core_ext/string/interpolate.rb +9 -0
  13. data/lib/i18n/exceptions.rb +1 -7
  14. data/lib/i18n/interpolate/ruby.rb +31 -0
  15. data/lib/i18n/locale/fallbacks.rb +3 -3
  16. data/lib/i18n/tests/localization/procs.rb +27 -26
  17. data/lib/i18n/version.rb +1 -1
  18. data/test/all.rb +8 -0
  19. data/test/api/all_features_test.rb +58 -0
  20. data/test/api/cascade_test.rb +28 -0
  21. data/test/api/chain_test.rb +24 -0
  22. data/test/api/fallbacks_test.rb +30 -0
  23. data/test/api/key_value_test.rb +28 -0
  24. data/test/api/memoize_test.rb +60 -0
  25. data/test/api/pluralization_test.rb +30 -0
  26. data/test/api/simple_test.rb +28 -0
  27. data/test/backend/cache_test.rb +83 -0
  28. data/test/backend/cascade_test.rb +85 -0
  29. data/test/backend/chain_test.rb +67 -0
  30. data/test/backend/exceptions_test.rb +23 -0
  31. data/test/backend/fallbacks_test.rb +116 -0
  32. data/test/backend/interpolation_compiler_test.rb +102 -0
  33. data/test/backend/key_value_test.rb +46 -0
  34. data/test/backend/memoize_test.rb +47 -0
  35. data/test/backend/metadata_test.rb +67 -0
  36. data/test/backend/pluralization_test.rb +44 -0
  37. data/test/backend/simple_test.rb +79 -0
  38. data/test/backend/transliterator_test.rb +81 -0
  39. data/test/core_ext/hash_test.rb +30 -0
  40. data/test/core_ext/string/interpolate_test.rb +99 -0
  41. data/test/gettext/api_test.rb +206 -0
  42. data/test/gettext/backend_test.rb +93 -0
  43. data/test/i18n/exceptions_test.rb +120 -0
  44. data/test/i18n/interpolate_test.rb +61 -0
  45. data/test/i18n/load_path_test.rb +26 -0
  46. data/test/i18n_test.rb +323 -0
  47. data/test/locale/fallbacks_test.rb +124 -0
  48. data/test/locale/tag/rfc4646_test.rb +142 -0
  49. data/test/locale/tag/simple_test.rb +32 -0
  50. data/test/run_all.rb +21 -0
  51. data/test/test_data/locales/de.po +72 -0
  52. data/test/test_data/locales/en.rb +3 -0
  53. data/test/test_data/locales/en.yml +3 -0
  54. data/test/test_data/locales/invalid/empty.yml +0 -0
  55. data/test/test_data/locales/plurals.rb +113 -0
  56. data/test/test_helper.rb +56 -0
  57. metadata +64 -48
  58. data/lib/i18n/backend/cldr.rb +0 -99
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzZlZTA2MGRlOTAzNTY4MGM1NmM2ODRhNjFjNWFkMTMyODNiNTU4Mg==
5
+ data.tar.gz: !binary |-
6
+ MGJmZmRhZjU1NGRlMzFjZjdjZDA2OWUxYWM3MmIwNmU0NzkyYmNmMA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YjkxZmU3MGJkZmM2ZDAxMjA0ZGI5OGNkYWZiNGU3MDEzNGZlYWU0YWNhNzQ2
10
+ YmE1ZDAzZGE2MjQyZDJiMTZlZGFiMTUyOThlYjdkYTQ4MGUxNmYwZjVhOGY5
11
+ ZTFkNDkzNzlmOWRlODVkMGI5YmY0ZTk5YmZjYTNhZTlhZjk4NDk=
12
+ data.tar.gz: !binary |-
13
+ YmQwN2ViOWZhMDkwYmZiMDgyODMyMjg0NjY0ZmViZTg4YThmYWU0NzVjNjRl
14
+ ZTk5NzhiMjVjMTExYjc5MzVkYTIwMDAyODI1YjFlZGM4YjY0MWM0NDNiZDZk
15
+ MTIxOTI1NWEwNjBkZDhjZTZmNmQ4MTBhNmQyNDhlNjFiNjlhY2I=
@@ -1,5 +1,14 @@
1
1
  h1. Changelog
2
2
 
3
+ h2. 0.5.0
4
+
5
+ * "Extract Backend::ActiveRecord to a separate gem":https://github.com/svenfuchs/i18n/commit/197dacebad356b910d69fa69a719c2ad10cf49e6 (see "i18n-active_record":https://github.com/svenfuchs/i18n-active_record)
6
+ * "Improve exception handling":https://github.com/svenfuchs/i18n/commit/2913ff9a7544f223f60e7d7b32c2a0e1af89812b (deprectates I18n.default_exception_handler)
7
+ * "Change MissingTranslationData message to 'translation missing: foo.bar'":https://github.com/svenfuchs/i18n/commit/68fdfe47952325411afe5942e971ce10b2bdf900
8
+ * "Expose MissingTranslationsData#keys method":https://github.com/svenfuchs/i18n/commit/3a37a389ecaac9670355b334e23e775549ee9822
9
+ * "Improve Cascade#lookup (add default options)":https://github.com/svenfuchs/i18n/commit/0b9a1f2058a2be9543106cc19d08071c359511e1
10
+ * "Finally remove deprecated interpolation syntax":https://github.com/svenfuchs/i18n/commit/2d43846d2b2a2e596f30fa58ea1c9ddb2243bb64
11
+
3
12
  h2. 0.4.2 (2010-10-26)
4
13
 
5
14
  * "Improve UTF8 handling":http://github.com/svenfuchs/i18n/commit/e8d5820a3b08eeca28de1a2b9c8a6ad2b9e6476c
@@ -44,7 +53,7 @@ h2. 0.3.6 (2010-03-23)
44
53
 
45
54
  h2. 0.3.5 (2010-02-26)
46
55
 
47
- * "Delegate I18n.normalize_translation_keys to I18n.normalize_keys and deprecate
56
+ * "Delegate I18n.normalize_translation_keys to I18n.normalize_keys and deprecate
48
57
  the former":http://github.com/svenfuchs/i18n/commit/7284b04d5f5dd9679cb68875515cdd0cdfc96fef
49
58
 
50
59
  h2. 0.3.4 (2010-02-25)
@@ -93,7 +102,7 @@ h2. 0.3.0 (2009-11-30)
93
102
  h2. 0.2.0 (2009-07-12)
94
103
 
95
104
  * "Allow using Ruby 1.9 syntax for string interpolation (API addition)":http://github.com/svenfuchs/i18n/commit/c6e0b06d512f2af57199a843a1d8a40241b32861
96
- * "Allow configuring the default scope separator, allow to pass a custom scope separator(API addition)":http://github.com/svenfuchs/i18n/commit/5b75bfbc348061adc11e3790187a187275bfd471 (e.g. I18n.t(:'foo|bar', :separator => '|')
105
+ * "Allow configuring the default scope separator, allow to pass a custom scope separator(API addition)":http://github.com/svenfuchs/i18n/commit/5b75bfbc348061adc11e3790187a187275bfd471 (e.g. I18n.t(:'foo|bar', :separator => '|')
97
106
  * "Pass :format option to #translate for #localize more useful lambda support":http://github.com/svenfuchs/i18n/commit/e277711b3c844fe7589b8d3f9af0f7d1b969a273
98
107
  * "Refactor Simple backend #resolve to #default and #resolve for more consistency. Now allows to pass lambdas as defaults and re-resolve Symbols":http://github.com/svenfuchs/i18n/commit/8c4ce3d923ce5fa73e973fe28217e18165549aba
99
108
  * "Add lambda support to #translate (API addition)":http://github.com/svenfuchs/i18n/commit/c90e62d8f7d3d5b78f34cfe328d871b58884f115
@@ -140,4 +149,4 @@ h2. More information
140
149
  * "Wiki":http://rails-i18n.org/wiki
141
150
  * "Mailinglist":http://groups.google.com/group/rails-i18n
142
151
  * "About the project/history":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
143
- * "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
152
+ * "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
@@ -64,25 +64,12 @@ h2. Tests
64
64
  You can run tests both with
65
65
 
66
66
  * `rake test` or just `rake`
67
- * run any test file directly, e.g. `ruby test/api/simple_test.rb`
68
- * run all tests with `ruby test/all.rb`
67
+ * run any test file directly, e.g. `ruby -Ilib -Itest test/api/simple_test.rb`
68
+ * run all tests with `ruby -Ilib -Itest test/all.rb`
69
69
 
70
- You can parametrize the test suite for using different sets of dependencies by
71
- using:
70
+ You can run all tests against all Gemfiles with
72
71
 
73
- .pre `ruby test/all.rb -w DEPENDENCIES`
74
-
75
- ... where DEPENDENCIES is a comma-separated list of:
76
-
77
- * r23 or rails-2.3.x
78
- * r3 or rails-3.x
79
- * no-rails
80
- * sqlite
81
- * mysql
82
-
83
- So, e.g. this would run the test suite against Rails 2.3.x using mysql:
84
-
85
- .pre `ruby test/all.rb -w r23,mysql`
72
+ * `ruby test/run_all.rb`
86
73
 
87
74
  The structure of the test suite is a bit unusual as it uses modules to reuse
88
75
  particular tests in different test cases.
@@ -1,13 +1,6 @@
1
- # Authors:: Sven Fuchs (http://www.artweb-design.de),
2
- # Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
3
- # Stephan Soller (http://www.arkanis-development.de/),
4
- # Saimon Moore (http://saimonmoore.net),
5
- # Matt Aimonetti (http://railsontherun.com/)
6
- # Copyright:: Copyright (c) 2008 The Ruby i18n Team
7
- # License:: MIT
8
1
  require 'i18n/version'
9
2
  require 'i18n/exceptions'
10
- require 'i18n/core_ext/string/interpolate'
3
+ require 'i18n/interpolate/ruby.rb'
11
4
 
12
5
  module I18n
13
6
  autoload :Backend, 'i18n/backend'
@@ -16,6 +9,9 @@ module I18n
16
9
  autoload :Locale, 'i18n/locale'
17
10
  autoload :Tests, 'i18n/tests'
18
11
 
12
+ RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :raise, :rescue_format]
13
+ RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
14
+
19
15
  class << self
20
16
  # Gets I18n configuration object.
21
17
  def config
@@ -316,7 +312,7 @@ module I18n
316
312
  end
317
313
 
318
314
  def handle_enforce_available_locales_deprecation
319
- if config.enforce_available_locales.nil? && !@unenforced_available_locales_deprecation
315
+ if config.enforce_available_locales.nil? && !defined?(@unenforced_available_locales_deprecation)
320
316
  $stderr.puts "[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message."
321
317
  @unenforced_available_locales_deprecation = true
322
318
  end
@@ -5,7 +5,6 @@ module I18n
5
5
  autoload :Cache, 'i18n/backend/cache'
6
6
  autoload :Cascade, 'i18n/backend/cascade'
7
7
  autoload :Chain, 'i18n/backend/chain'
8
- autoload :Cldr, 'i18n/backend/cldr'
9
8
  autoload :Fallbacks, 'i18n/backend/fallbacks'
10
9
  autoload :Flatten, 'i18n/backend/flatten'
11
10
  autoload :Gettext, 'i18n/backend/gettext'
@@ -1,14 +1,12 @@
1
1
  require 'yaml'
2
2
  require 'i18n/core_ext/hash'
3
+ require 'i18n/core_ext/kernel/surpress_warnings'
3
4
 
4
5
  module I18n
5
6
  module Backend
6
7
  module Base
7
8
  include I18n::Backend::Transliterator
8
9
 
9
- RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback]
10
- RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
11
-
12
10
  # Accepts a list of paths to translation files. Loads translations from
13
11
  # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml
14
12
  # for details.
@@ -140,34 +138,14 @@ module I18n
140
138
  #
141
139
  # interpolate "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
142
140
  # # => "file test.txt opened by %{user}"
143
- #
144
- # Note that you have to double escape the <tt>\\</tt> when you want to escape
145
- # the <tt>{{...}}</tt> key in a string (once for the string and once for the
146
- # interpolation).
147
141
  def interpolate(locale, string, values = {})
148
- return string unless string.is_a?(::String) && !values.empty?
149
-
150
- values.each do |key, value|
151
- value = value.call(values) if interpolate_lambda?(value, string, key)
152
- value = value.to_s unless value.is_a?(::String)
153
- values[key] = value
154
- end
155
-
156
- string % values
157
- rescue KeyError => e
158
- if string =~ RESERVED_KEYS_PATTERN
159
- raise ReservedInterpolationKey.new($1.to_sym, string)
142
+ if string.is_a?(::String) && !values.empty?
143
+ I18n.interpolate(string, values)
160
144
  else
161
- raise MissingInterpolationArgument.new(values, string)
145
+ string
162
146
  end
163
147
  end
164
148
 
165
- # returns true when the given value responds to :call and the key is
166
- # an interpolation placeholder in the given string
167
- def interpolate_lambda?(object, string, key)
168
- object.respond_to?(:call) && string =~ /%\{#{key}\}|%\<#{key}>.*?\d*\.?\d*[bBdiouxXeEfgGcps]\}/
169
- end
170
-
171
149
  # Loads a single translations file by delegating to #load_rb or
172
150
  # #load_yml depending on the file extension and directly merges the
173
151
  # data to the existing translations. Raises I18n::UnknownFileType
@@ -191,12 +169,6 @@ module I18n
191
169
  def load_yml(filename)
192
170
  YAML.load_file(filename)
193
171
  end
194
-
195
- def warn_syntax_deprecation!(locale, string) #:nodoc:
196
- return if @skip_syntax_deprecation
197
- warn "The {{key}} interpolation syntax in I18n messages is deprecated. Please use %{key} instead.\n#{locale} - #{string}\n"
198
- @skip_syntax_deprecation = true
199
- end
200
172
  end
201
173
  end
202
174
  end
@@ -43,8 +43,8 @@ module I18n
43
43
  key, value = normalize_pluralization(locale, key, value) if key.index("\000")
44
44
 
45
45
  parts = key.split('|').reverse
46
- normalized = parts.inject({}) do |normalized, part|
47
- normalized = { part => normalized.empty? ? value : normalized }
46
+ normalized = parts.inject({}) do |_normalized, part|
47
+ { part => _normalized.empty? ? value : _normalized }
48
48
  end
49
49
 
50
50
  result.deep_merge!(normalized)
@@ -62,7 +62,7 @@ module I18n
62
62
  raise "invalid number of plurals: #{values.size}, keys: #{keys.inspect}" if values.size != keys.size
63
63
 
64
64
  result = {}
65
- values.each_with_index { |value, ix| result[keys[ix]] = value }
65
+ values.each_with_index { |_value, ix| result[keys[ix]] = _value }
66
66
  [key, result]
67
67
  end
68
68
 
@@ -61,7 +61,7 @@ module I18n
61
61
 
62
62
  def interpolate_or_raise_missing(key)
63
63
  escaped_key = escape_key_sym(key)
64
- Base::RESERVED_KEYS.include?(key) ? reserved_key(escaped_key) : interpolate_key(escaped_key)
64
+ RESERVED_KEYS.include?(key) ? reserved_key(escaped_key) : interpolate_key(escaped_key)
65
65
  end
66
66
 
67
67
  def interpolate_key(key)
@@ -38,7 +38,7 @@ module I18n
38
38
  :scope => options[:scope],
39
39
  :default => options[:default],
40
40
  :separator => options[:separator],
41
- :values => options.reject { |name, value| Base::RESERVED_KEYS.include?(name) }
41
+ :values => options.reject { |name, value| RESERVED_KEYS.include?(name) }
42
42
  }
43
43
  with_metadata(metadata) { super }
44
44
  end
@@ -43,7 +43,7 @@ module I18n
43
43
 
44
44
  # Sets the available locales.
45
45
  def available_locales=(locales)
46
- @@available_locales = Array(locales).map {|locale| locale.to_sym}
46
+ @@available_locales = Array(locales).map { |locale| locale.to_sym }
47
47
  @@available_locales = nil if @@available_locales.empty?
48
48
  end
49
49
 
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ def suppress_warnings
3
+ original_verbosity = $VERBOSE
4
+ $VERBOSE = nil
5
+ result = yield
6
+ $VERBOSE = original_verbosity
7
+ result
8
+ end
9
+ end
@@ -1,3 +1,12 @@
1
+ # This backports the Ruby 1.9 String interpolation syntax to Ruby 1.8.
2
+ #
3
+ # This backport has been shipped with I18n for a number of versions. Meanwhile
4
+ # Rails has started to rely on it and we are going to move it to ActiveSupport.
5
+ # See https://rails.lighthouseapp.com/projects/8994/tickets/6013-move-19-string-interpolation-syntax-backport-from-i18n-to-activesupport
6
+ #
7
+ # Once the above patch has been applied to Rails the following code will be
8
+ # removed from I18n.
9
+
1
10
  =begin
2
11
  heavily based on Masao Mutoh's gettext String interpolation extension
3
12
  http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
@@ -1,11 +1,5 @@
1
1
  require 'cgi'
2
2
 
3
- class KeyError < IndexError
4
- def initialize(message = nil)
5
- super(message || "key not found")
6
- end
7
- end unless defined?(KeyError)
8
-
9
3
  module I18n
10
4
  # Handles exceptions raised in the backend. All exceptions except for
11
5
  # MissingTranslationData exceptions are re-raised. When a MissingTranslationData
@@ -19,7 +13,7 @@ module I18n
19
13
  # TODO: this block is to be replaced by `exception.message` when
20
14
  # rescue_format is removed
21
15
  if options[:rescue_format] == :html
22
- if @rescue_format_deprecation
16
+ if !defined?(@rescue_format_deprecation)
23
17
  $stderr.puts "[DEPRECATED] I18n's :recue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler."
24
18
  @rescue_format_deprecation = true
25
19
  end
@@ -0,0 +1,31 @@
1
+ # heavily based on Masao Mutoh's gettext String interpolation extension
2
+ # http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
3
+
4
+ module I18n
5
+ INTERPOLATION_PATTERN = Regexp.union(
6
+ /%%/,
7
+ /%\{(\w+)\}/, # matches placeholders like "%{foo}"
8
+ /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
9
+ )
10
+
11
+ class << self
12
+ def interpolate(string, values)
13
+ raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ RESERVED_KEYS_PATTERN
14
+ raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash)
15
+ interpolate_hash(string, values)
16
+ end
17
+
18
+ def interpolate_hash(string, values)
19
+ string.gsub(INTERPOLATION_PATTERN) do |match|
20
+ if match == '%%'
21
+ '%'
22
+ else
23
+ key = ($1 || $2).to_sym
24
+ value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
25
+ value = value.call(values) if value.respond_to?(:call)
26
+ $3 ? sprintf("%#{$3}", value) : value
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -73,9 +73,9 @@ module I18n
73
73
  def map(mappings)
74
74
  mappings.each do |from, to|
75
75
  from, to = from.to_sym, Array(to)
76
- to.each do |to|
76
+ to.each do |_to|
77
77
  @map[from] ||= []
78
- @map[from] << to.to_sym
78
+ @map[from] << _to.to_sym
79
79
  end
80
80
  end
81
81
  end
@@ -85,7 +85,7 @@ module I18n
85
85
  def compute(tags, include_defaults = true)
86
86
  result = Array(tags).collect do |tag|
87
87
  tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym }
88
- tags.each { |tag| tags += compute(@map[tag]) if @map[tag] }
88
+ tags.each { |_tag| tags += compute(@map[_tag]) if @map[_tag] }
89
89
  tags
90
90
  end.flatten
91
91
  result.push(*defaults) if include_defaults
@@ -1,17 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- class DateTime
4
- def inspect
5
- strftime('%a, %d %b %Y %H:%M:%S %Z')
6
- end
7
- end
8
-
9
- class Date
10
- def inspect
11
- strftime('%a, %d %b %Y')
12
- end
13
- end
14
-
15
3
  module I18n
16
4
  module Tests
17
5
  module Localization
@@ -19,33 +7,33 @@ module I18n
19
7
  test "localize: using day names from lambdas" do
20
8
  setup_time_proc_translations
21
9
  time = ::Time.utc(2008, 3, 1, 6, 0)
22
- assert_match /Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru)
23
- assert_match /суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru)
10
+ assert_match(/Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru))
11
+ assert_match(/суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru))
24
12
  end
25
13
 
26
14
  test "localize: using month names from lambdas" do
27
15
  setup_time_proc_translations
28
16
  time = ::Time.utc(2008, 3, 1, 6, 0)
29
- assert_match /марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru)
30
- assert_match /Март /, I18n.l(time, :format => "%B %Y", :locale => :ru)
17
+ assert_match(/марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru))
18
+ assert_match(/Март /, I18n.l(time, :format => "%B %Y", :locale => :ru))
31
19
  end
32
20
 
33
21
  test "localize: using abbreviated day names from lambdas" do
34
22
  setup_time_proc_translations
35
23
  time = ::Time.utc(2008, 3, 1, 6, 0)
36
- assert_match /марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru)
37
- assert_match /март /, I18n.l(time, :format => "%b %Y", :locale => :ru)
24
+ assert_match(/марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru))
25
+ assert_match(/март /, I18n.l(time, :format => "%b %Y", :locale => :ru))
38
26
  end
39
27
 
40
28
  test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
41
29
  setup_time_proc_translations
42
- date = ::Date.new(2008, 3, 1, 6)
30
+ date = ::Date.new(2008, 3, 1)
43
31
  assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(date, :format => :proc, :locale => :ru)
44
32
  end
45
33
 
46
34
  test "localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
47
35
  setup_time_proc_translations
48
- date = ::Date.new(2008, 3, 1, 6)
36
+ date = ::Date.new(2008, 3, 1)
49
37
  assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
50
38
  end
51
39
 
@@ -64,32 +52,45 @@ module I18n
64
52
  test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
65
53
  setup_time_proc_translations
66
54
  time = ::Time.utc(2008, 3, 1, 6, 0)
67
- assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
55
+ assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru)
68
56
  end
69
57
 
70
58
  test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
71
59
  setup_time_proc_translations
72
60
  time = ::Time.utc(2008, 3, 1, 6, 0)
73
61
  options = { :foo => 'foo' }
74
- assert_equal [time, options].inspect, I18n.l(time, options.merge(:format => :proc, :locale => :ru))
62
+ assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
75
63
  end
76
64
 
77
65
  protected
78
66
 
79
- def filter_args(*args)
80
- args.map { |arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
67
+ def inspect_args(args)
68
+ args = args.map do |arg|
69
+ case arg
70
+ when ::Time, ::DateTime
71
+ arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
72
+ when ::Date
73
+ arg.strftime('%a, %d %b %Y')
74
+ when Hash
75
+ arg.delete(:fallback)
76
+ arg.inspect
77
+ else
78
+ arg.inspect
79
+ end
80
+ end
81
+ "[#{args.join(', ')}]"
81
82
  end
82
83
 
83
84
  def setup_time_proc_translations
84
85
  I18n.backend.store_translations :ru, {
85
86
  :time => {
86
87
  :formats => {
87
- :proc => lambda { |*args| filter_args(*args) }
88
+ :proc => lambda { |*args| inspect_args(args) }
88
89
  }
89
90
  },
90
91
  :date => {
91
92
  :formats => {
92
- :proc => lambda { |*args| filter_args(*args) }
93
+ :proc => lambda { |*args| inspect_args(args) }
93
94
  },
94
95
  :'day_names' => lambda { |key, options|
95
96
  (options[:format] =~ /^%A/) ?