i18n 1.14.1 → 1.14.3

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: 692bec57675f1d97cdd0dff4a7b444e1777ba2f360dc3cf7162d5a98e45ab0a5
4
- data.tar.gz: 954df8c7788ce253f730e4bf6911373198b26c24c2274113b2e12b6d6527b486
3
+ metadata.gz: ea48f292aece0bdb7828a9105d15760ad8668254eecd8877e312f8381d179f6a
4
+ data.tar.gz: ba1a7fe8f3998571013e4c72fcd8c047944ecdc6d0561058e03dd5a5242b1020
5
5
  SHA512:
6
- metadata.gz: 26ebf6f4edea8d2a6cf511496bcad2c0e50323c44263c4d27e44f12860f9e4e35e093514bb1fb3cd9925591b5e3db62917af79ee2710b4cc759735dd1ff4d538
7
- data.tar.gz: 1764731c2157cddb200a8dec9286248f7fac4e8a23548305aa09e70b5591d924748179c9534bb46cd6d7d892987963566d95e20854d5928b51a0fbad76dded3b
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
@@ -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)
@@ -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.1"
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.1
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-04 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