i18n 1.14.5 → 1.14.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e29c720198c6fd20a8ec55a99ad4ce81c2ff09abf74a55ee6e09513ac17546c
4
- data.tar.gz: 6ad9b851da6ba7c857dbd79b9e817493f7eaba91be46f16cec3a86cb94c32c11
3
+ metadata.gz: abb47988c5f7107e7752235391d3841b093b22129643b5800fe208fd885c238a
4
+ data.tar.gz: 95343bb49011a881932676ca8e561a28e0779b1972893d9ece8c012886ac862c
5
5
  SHA512:
6
- metadata.gz: 7de3901b122039da2a99507e40dbe5e57ce8e5622c14591ebf251adf563c763f55d2f1fb1bc7d54c5f2be427a37b81839e636de7eee434a53ab80a39c4f8bf53
7
- data.tar.gz: 1bfd4bd7c5dd8de6df524ae64d652e2f785955a1928bd3bca66e3ba8515e2d4d60c83ff576c51ca84e744625874145c0850f301b8d2fd6090c226541ad389575
6
+ metadata.gz: bdeb6008dae46d97da006f84446c0be3a81ffe8fe275ea4a6866673e663b13664fc225c3dcc7314c0db4aa4ef269a8fbcb6b58b5a359452de90625e1a826ff6d
7
+ data.tar.gz: ca01e033ca49fb385a3e05b3ff72bbfd5a5f256e22379f564367e72eabe125beb0c418654fb423523077a0a9aece57ad9e94d72ee646e5a6483e3e7e14525cc3
@@ -54,8 +54,9 @@ module I18n
54
54
  end
55
55
 
56
56
  deep_interpolation = options[:deep_interpolation]
57
+ skip_interpolation = options[:skip_interpolation]
57
58
  values = Utils.except(options, *RESERVED_KEYS) unless options.empty?
58
- if values && !values.empty?
59
+ if !skip_interpolation && values && !values.empty?
59
60
  entry = if deep_interpolation
60
61
  deep_interpolate(locale, entry, values)
61
62
  else
@@ -151,7 +152,14 @@ module I18n
151
152
  result = catch(:exception) do
152
153
  case subject
153
154
  when Symbol
154
- I18n.translate(subject, **options.merge(:locale => locale, :throw => true))
155
+ I18n.translate(
156
+ subject,
157
+ **options.merge(
158
+ :locale => locale,
159
+ :throw => true,
160
+ :skip_interpolation => true
161
+ )
162
+ )
155
163
  when Proc
156
164
  date_or_time = options.delete(:object) || object
157
165
  resolve(locale, object, subject.call(date_or_time, **options))
@@ -244,7 +252,7 @@ module I18n
244
252
  # Loads a plain Ruby translations file. eval'ing the file must yield
245
253
  # a Hash containing translation data with locales as toplevel keys.
246
254
  def load_rb(filename)
247
- translations = eval(IO.read(filename), binding, filename)
255
+ translations = eval(IO.read(filename), binding, filename.to_s)
248
256
  [translations, false]
249
257
  end
250
258
 
@@ -71,7 +71,11 @@ module I18n
71
71
 
72
72
  case subject
73
73
  when Symbol
74
- I18n.translate(subject, **options.merge(:locale => options[:fallback_original_locale], :throw => true))
74
+ I18n.translate(subject, **options.merge(
75
+ :locale => options[:fallback_original_locale],
76
+ :throw => true,
77
+ :skip_interpolation => true
78
+ ))
75
79
  when Proc
76
80
  date_or_time = options.delete(:object) || object
77
81
  resolve_entry(options[:fallback_original_locale], object, subject.call(date_or_time, **options))
@@ -10,14 +10,14 @@ module I18n
10
10
  # The implementation is provided by a Implementation module allowing to easily
11
11
  # extend Simple backend's behavior by including modules. E.g.:
12
12
  #
13
- # module I18n::Backend::Pluralization
14
- # def pluralize(*args)
15
- # # extended pluralization logic
16
- # super
17
- # end
18
- # end
19
- #
20
- # I18n::Backend::Simple.include(I18n::Backend::Pluralization)
13
+ # module I18n::Backend::Pluralization
14
+ # def pluralize(*args)
15
+ # # extended pluralization logic
16
+ # super
17
+ # end
18
+ # end
19
+ #
20
+ # I18n::Backend::Simple.include(I18n::Backend::Pluralization)
21
21
  class Simple
22
22
  module Implementation
23
23
  include Base
@@ -47,6 +47,13 @@ module I18n
47
47
  I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
48
48
  assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
49
49
  end
50
+
51
+ # Addresses issue: #599
52
+ test "defaults: only interpolates once when resolving defaults" do
53
+ I18n.backend.store_translations(:en, :greeting => 'hey %{name}')
54
+ assert_equal 'hey %{dont_interpolate_me}',
55
+ I18n.t(:does_not_exist, :name => '%{dont_interpolate_me}', default: [:greeting])
56
+ end
50
57
  end
51
58
  end
52
59
  end
@@ -76,6 +76,12 @@ module I18n
76
76
  test "lookup: a resulting Hash is not frozen" do
77
77
  assert !I18n.t(:hash).frozen?
78
78
  end
79
+
80
+ # Addresses issue: #599
81
+ test "lookup: only interpolates once when resolving symbols" do
82
+ I18n.backend.store_translations(:en, foo: :bar, bar: '%{value}')
83
+ assert_equal '%{dont_interpolate_me}', I18n.t(:foo, value: '%{dont_interpolate_me}')
84
+ end
79
85
  end
80
86
  end
81
87
  end
@@ -57,6 +57,7 @@ module I18n
57
57
  if arg.is_a?(Hash)
58
58
  arg.delete(:fallback_in_progress)
59
59
  arg.delete(:fallback_original_locale)
60
+ arg.delete(:skip_interpolation)
60
61
  end
61
62
  arg
62
63
  end.inspect
data/lib/i18n/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.14.5"
4
+ VERSION = "1.14.6"
5
5
  end
data/lib/i18n.rb CHANGED
@@ -19,6 +19,7 @@ module I18n
19
19
  RESERVED_KEYS = %i[
20
20
  cascade
21
21
  deep_interpolation
22
+ skip_interpolation
22
23
  default
23
24
  exception_handler
24
25
  fallback
@@ -161,7 +162,7 @@ module I18n
161
162
  # or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
162
163
  # I18n.t :foo, :default => [:bar, 'default']
163
164
  #
164
- # *BULK LOOKUP*
165
+ # <b>BULK LOOKUP</b>
165
166
  #
166
167
  # This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
167
168
  # I18n.t [:foo, :bar]
@@ -180,7 +181,7 @@ module I18n
180
181
  # E.g. assuming the key <tt>:salutation</tt> resolves to:
181
182
  # lambda { |key, options| options[:gender] == 'm' ? "Mr. #{options[:name]}" : "Mrs. #{options[:name]}" }
182
183
  #
183
- # Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith".
184
+ # Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith')</tt> will result in "Mrs. Smith".
184
185
  #
185
186
  # Note that the string returned by lambda will go through string interpolation too,
186
187
  # so the following lambda would give the same result:
@@ -192,7 +193,7 @@ module I18n
192
193
  # always return the same translations/values per unique combination of argument
193
194
  # values.
194
195
  #
195
- # *Ruby 2.7+ keyword arguments warning*
196
+ # <b>Ruby 2.7+ keyword arguments warning</b>
196
197
  #
197
198
  # This method uses keyword arguments.
198
199
  # There is a breaking change in ruby that produces warning with ruby 2.7 and won't work as expected with ruby 3.0
@@ -264,7 +265,8 @@ module I18n
264
265
  def exists?(key, _locale = nil, locale: _locale, **options)
265
266
  locale ||= config.locale
266
267
  raise Disabled.new('exists?') if locale == false
267
- raise I18n::ArgumentError if key.is_a?(String) && key.empty?
268
+ raise I18n::ArgumentError if (key.is_a?(String) && key.empty?) || key.nil?
269
+
268
270
  config.backend.exists?(locale, key, options)
269
271
  end
270
272
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.5
4
+ version: 1.14.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2024-05-06 00:00:00.000000000 Z
16
+ date: 2024-09-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -91,7 +91,10 @@ metadata:
91
91
  changelog_uri: https://github.com/ruby-i18n/i18n/releases
92
92
  documentation_uri: https://guides.rubyonrails.org/i18n.html
93
93
  source_code_uri: https://github.com/ruby-i18n/i18n
94
- post_install_message:
94
+ post_install_message: 'PSA: I18n will be dropping support for Ruby < 3.2 in the next
95
+ major release (April 2025), due to Ruby''s end of life for 3.1 and below (https://endoflife.date/ruby).
96
+ Please upgrade to Ruby 3.2 or newer by April 2025 to continue using future versions
97
+ of this gem.'
95
98
  rdoc_options: []
96
99
  require_paths:
97
100
  - lib
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  - !ruby/object:Gem::Version
107
110
  version: 1.3.5
108
111
  requirements: []
109
- rubygems_version: 3.5.1
112
+ rubygems_version: 3.3.27
110
113
  signing_key:
111
114
  specification_version: 4
112
115
  summary: New wave Internationalization support for Ruby