i18n 1.14.0 → 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56f42c8544a7ce959616902c3a1dcabe350581001f708b43883504995c29835a
4
- data.tar.gz: 8502fbd1b16386dc75b9feac93e023915671ade132423b04538324e8c855de8c
3
+ metadata.gz: ea48f292aece0bdb7828a9105d15760ad8668254eecd8877e312f8381d179f6a
4
+ data.tar.gz: ba1a7fe8f3998571013e4c72fcd8c047944ecdc6d0561058e03dd5a5242b1020
5
5
  SHA512:
6
- metadata.gz: 8b19cf52d0c49c3f521d3917958b47a235d61d374af806ade81da6092bf68577153012cf98cb61c85b4f951284a96aeace9280c8ca64d78e6f0b7546ef3f8d64
7
- data.tar.gz: ac025237950bb63b2f66ff28ceb9cadb9de16bd9b55853ee47a48f61552c5192805bbc4415e4f8394481c74130c8163938707cf861ad65d58438636be096ccae
6
+ metadata.gz: 0b8fdf47e5b10f58a8a214527ab5cece35ba22fb08df89e5f258fc3436a5d5be55318222f667c027025df2535d8acf0177f1ee3a5c16efa1b6e85aa3a50e9ad2
7
+ data.tar.gz: 77925068fc786fa599830414bc466da240254754be3b6e64929e4becb1ae678ad50220128caee95fad963c916b3c8c2cc5bf3766944c8b9d067aaaccf1c6e384
data/README.md CHANGED
@@ -13,10 +13,14 @@ Currently maintained by @radar.
13
13
 
14
14
  You will most commonly use this library within a Rails app.
15
15
 
16
+ We support Rails versions from 6.0 and up.
17
+
16
18
  [See the Rails Guide](https://guides.rubyonrails.org/i18n.html) for an example of its usage.
17
19
 
18
20
  ### Ruby (without Rails)
19
21
 
22
+ We support Ruby versions from 3.0 and up.
23
+
20
24
  If you want to use this library without Rails, you can simply add `i18n` to your `Gemfile`:
21
25
 
22
26
  ```ruby
@@ -55,12 +55,14 @@ module I18n
55
55
 
56
56
  deep_interpolation = options[:deep_interpolation]
57
57
  values = Utils.except(options, *RESERVED_KEYS) unless options.empty?
58
- if values
58
+ if values && !values.empty?
59
59
  entry = if deep_interpolation
60
60
  deep_interpolate(locale, entry, values)
61
61
  else
62
62
  interpolate(locale, entry, values)
63
63
  end
64
+ elsif entry.is_a?(String) && entry =~ I18n.reserved_keys_pattern
65
+ raise ReservedInterpolationKey.new($1.to_sym, entry)
64
66
  end
65
67
  entry
66
68
  end
@@ -16,6 +16,8 @@ module I18n
16
16
  #
17
17
  # The implementation assumes that all backends added to the Chain implement
18
18
  # a lookup method with the same API as Simple backend does.
19
+ #
20
+ # Fallback translations using the :default option are only used by the last backend of a chain.
19
21
  class Chain
20
22
  module Implementation
21
23
  include Base
@@ -95,7 +95,7 @@ module I18n
95
95
  return super unless options.fetch(:fallback, true)
96
96
  I18n.fallbacks[locale].each do |fallback|
97
97
  begin
98
- return true if super(fallback, key)
98
+ return true if super(fallback, key, options)
99
99
  rescue I18n::InvalidLocale
100
100
  # we do nothing when the locale is invalid, as this is a fallback anyways.
101
101
  end
@@ -21,8 +21,7 @@ module I18n
21
21
  module Compiler
22
22
  extend self
23
23
 
24
- TOKENIZER = /(%%\{[^\}]+\}|%\{[^\}]+\})/
25
- INTERPOLATION_SYNTAX_PATTERN = /(%)?(%\{([^\}]+)\})/
24
+ TOKENIZER = /(%%?\{[^}]+\})/
26
25
 
27
26
  def compile_if_an_interpolation(string)
28
27
  if interpolated_str?(string)
@@ -37,7 +36,7 @@ module I18n
37
36
  end
38
37
 
39
38
  def interpolated_str?(str)
40
- str.kind_of?(::String) && str =~ INTERPOLATION_SYNTAX_PATTERN
39
+ str.kind_of?(::String) && str =~ TOKENIZER
41
40
  end
42
41
 
43
42
  protected
@@ -48,13 +47,12 @@ module I18n
48
47
 
49
48
  def compiled_interpolation_body(str)
50
49
  tokenize(str).map do |token|
51
- (matchdata = token.match(INTERPOLATION_SYNTAX_PATTERN)) ? handle_interpolation_token(token, matchdata) : escape_plain_str(token)
50
+ token.match(TOKENIZER) ? handle_interpolation_token(token) : escape_plain_str(token)
52
51
  end.join
53
52
  end
54
53
 
55
- def handle_interpolation_token(interpolation, matchdata)
56
- escaped, pattern, key = matchdata.values_at(1, 2, 3)
57
- escaped ? pattern : compile_interpolation_token(key.to_sym)
54
+ def handle_interpolation_token(token)
55
+ token.start_with?('%%') ? token[1..] : compile_interpolation_token(token[2..-2])
58
56
  end
59
57
 
60
58
  def compile_interpolation_token(key)
@@ -63,8 +63,8 @@ module I18n
63
63
  end
64
64
 
65
65
  def message
66
- if options[:default].is_a?(Array)
67
- other_options = ([key, *options[:default]]).map { |k| normalized_option(k).prepend('- ') }.join("\n")
66
+ if (default = options[:default]).is_a?(Array) && default.any?
67
+ other_options = ([key, *default]).map { |k| normalized_option(k).prepend('- ') }.join("\n")
68
68
  "Translation missing. Options considered were:\n#{other_options}"
69
69
  else
70
70
  "Translation missing: #{keys.join('.')}"
@@ -79,6 +79,14 @@ module I18n
79
79
  end
80
80
  end
81
81
 
82
+ def empty?
83
+ @map.empty? && @defaults.empty?
84
+ end
85
+
86
+ def inspect
87
+ "#<#{self.class.name} @map=#{@map.inspect} @defaults=#{@defaults.inspect}>"
88
+ end
89
+
82
90
  protected
83
91
 
84
92
  def compute(tags, include_defaults = true, exclude = [])
@@ -112,6 +112,10 @@ module I18n
112
112
  assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{default}') }
113
113
  assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{separator}') }
114
114
  assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{scope}') }
115
+ assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '%{scope}') }
116
+
117
+ I18n.backend.store_translations(:en, :interpolate => 'Hi %{scope}!')
118
+ assert_raises(I18n::ReservedInterpolationKey) { interpolate(:interpolate) }
115
119
  end
116
120
 
117
121
  test "interpolation: deep interpolation for default string" do
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.0"
4
+ VERSION = "1.14.3"
5
5
  end
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.0
4
+ version: 1.14.3
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: 2023-06-02 00:00:00.000000000 Z
16
+ date: 2024-03-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -29,6 +29,20 @@ dependencies:
29
29
  - - "~>"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '1.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: racc
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.7'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.7'
32
46
  description: New wave Internationalization support for Ruby.
33
47
  email: rails-i18n@googlegroups.com
34
48
  executables: []
@@ -106,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  - !ruby/object:Gem::Version
107
121
  version: 1.3.5
108
122
  requirements: []
109
- rubygems_version: 3.3.16
123
+ rubygems_version: 3.5.1
110
124
  signing_key:
111
125
  specification_version: 4
112
126
  summary: New wave Internationalization support for Ruby