i18n 1.6.0 → 1.7.0

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: 2b03b84d726d3cafa7ea2ecaa6f258cb911696c338cb32c769f71b6d62ca5fb5
4
- data.tar.gz: 7a489bf447e9fedee8fd043cc8ba324c0afc0c34701fbfeff5f15b1c1f4fa6b4
3
+ metadata.gz: dd80c4dac859bf40aa5a70cab46357ea469fe054757dc747d8976a243e619bb0
4
+ data.tar.gz: f396a7f27e9295a336dbccc489828439816de7dbc7b7fd5f8bd7863c907d813a
5
5
  SHA512:
6
- metadata.gz: 534659c40a8df9eb3fd9a123b779de0f1b66471ecd3fb35e2083128193f51aeea95df6aad06039b6309932a6efb3426c525a8759e70c1104754fdd921732d6cd
7
- data.tar.gz: caddebe447a797be3dde1607e74d826588ee13ee1317c6abfbb08cbd8a22d79a6aa10a84d3fd21fa45ca9348317aa0e0aafe1c408d4e1c989fbee7f09cd87606
6
+ metadata.gz: 1be60c0724e1bb2054dfaecc1f732d3a6d52e2eaa600947899938f591b0cbb3af43614d57e2157d9f6a35f18b8b3119e65cba605b32cef33c4e361be2e84f9aa
7
+ data.tar.gz: 973b4f37394853d37b10a8801cc6d3b33f934601ccd492a1c93df6f05c13cb780068403c4e12216d0a831489babd0fcec9eb04ad0c68ebbaf57a94b76ad24ed2
data/README.md CHANGED
@@ -95,7 +95,7 @@ particular tests in different test cases.
95
95
  The reason for this is that we need to enforce the I18n API across various
96
96
  combinations of extensions. E.g. the Simple backend alone needs to support
97
97
  the same API as any combination of feature and/or optimization modules included
98
- to the Simple backend. We test this by reusing the same API defition (implemented
98
+ to the Simple backend. We test this by reusing the same API definition (implemented
99
99
  as test methods) in test cases with different setups.
100
100
 
101
101
  You can find the test cases that enforce the API in test/api. And you can find
@@ -115,7 +115,7 @@ module I18n
115
115
  # *PLURALIZATION*
116
116
  #
117
117
  # Translation data can contain pluralized translations. Pluralized translations
118
- # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
118
+ # are arrays of singular/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
119
119
  #
120
120
  # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
121
121
  # pluralization rules. Other algorithms can be supported by custom backends.
@@ -173,7 +173,7 @@ module I18n
173
173
  #
174
174
  # It is recommended to use/implement lambdas in an "idempotent" way. E.g. when
175
175
  # a cache layer is put in front of I18n.translate it will generate a cache key
176
- # from the argument values passed to #translate. Therefor your lambdas should
176
+ # from the argument values passed to #translate. Therefore your lambdas should
177
177
  # always return the same translations/values per unique combination of argument
178
178
  # values.
179
179
  def translate(key = nil, *, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
@@ -202,7 +202,7 @@ module I18n
202
202
  # Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
203
203
  # this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
204
204
  def translate!(key, options = EMPTY_HASH)
205
- translate(key, options.merge(:raise => true))
205
+ translate(key, **options.merge(:raise => true))
206
206
  end
207
207
  alias :t! :translate!
208
208
 
@@ -81,7 +81,7 @@ module I18n
81
81
  key = format
82
82
  type = object.respond_to?(:sec) ? 'time' : 'date'
83
83
  options = options.merge(:raise => true, :object => object, :locale => locale)
84
- format = I18n.t(:"#{type}.formats.#{key}", options)
84
+ format = I18n.t(:"#{type}.formats.#{key}", **options)
85
85
  end
86
86
 
87
87
  format = translate_localization_format(locale, object, format, options)
@@ -122,7 +122,7 @@ module I18n
122
122
  # first translation that can be resolved. Otherwise it tries to resolve
123
123
  # the translation directly.
124
124
  def default(locale, object, subject, options = EMPTY_HASH)
125
- options = options.dup.reject { |key, value| key == :default }
125
+ options = options.reject { |key, value| key == :default }
126
126
  case subject
127
127
  when Array
128
128
  subject.each do |item|
@@ -143,7 +143,7 @@ module I18n
143
143
  result = catch(:exception) do
144
144
  case subject
145
145
  when Symbol
146
- I18n.translate(subject, options.merge(:locale => locale, :throw => true))
146
+ I18n.translate(subject, **options.merge(:locale => locale, :throw => true))
147
147
  when Proc
148
148
  date_or_time = options.delete(:object) || object
149
149
  resolve(locale, object, subject.call(date_or_time, options))
@@ -96,9 +96,13 @@ module I18n
96
96
  end
97
97
 
98
98
  def translations
99
- backends.first.instance_eval do
100
- init_translations unless initialized?
101
- translations
99
+ backends.reverse.each_with_object({}) do |backend, memo|
100
+ partial_translations = backend.instance_eval do
101
+ init_translations unless initialized?
102
+ translations
103
+ end
104
+
105
+ memo.deep_merge!(partial_translations)
102
106
  end
103
107
  end
104
108
 
@@ -21,8 +21,6 @@ module I18n
21
21
  class Simple
22
22
  using I18n::HashRefinements
23
23
 
24
- (class << self; self; end).class_eval { public :include }
25
-
26
24
  module Implementation
27
25
  include Base
28
26
 
@@ -19,7 +19,7 @@ module I18n
19
19
  end
20
20
 
21
21
  def gettext(msgid, options = EMPTY_HASH)
22
- I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
22
+ I18n.t(msgid, **{:default => msgid, :separator => '|'}.merge(options))
23
23
  end
24
24
  alias _ gettext
25
25
 
@@ -4,7 +4,7 @@
4
4
  module I18n
5
5
  DEFAULT_INTERPOLATION_PATTERNS = [
6
6
  /%%/,
7
- /%\{(\w+)\}/, # matches placeholders like "%{foo}"
7
+ /%\{([\w|]+)\}/, # matches placeholders like "%{foo} or %{foo|word}"
8
8
  /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
9
9
  ].freeze
10
10
  INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)
@@ -66,6 +66,7 @@ module I18n
66
66
 
67
67
  def [](locale)
68
68
  raise InvalidLocale.new(locale) if locale.nil?
69
+ raise Disabled.new('fallback#[]') if locale == false
69
70
  locale = locale.to_sym
70
71
  super || store(locale, compute(locale))
71
72
  end
@@ -24,6 +24,10 @@ module I18n
24
24
  assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
25
25
  end
26
26
 
27
+ test "interpolation: works with a pipe" do
28
+ assert_equal 'Hi david!', interpolate(:default => 'Hi %{name|lowercase}!', :'name|lowercase' => 'david')
29
+ end
30
+
27
31
  test "interpolation: given a nil value it still interpolates it into the string" do
28
32
  assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
29
33
  end
@@ -68,9 +68,9 @@ module I18n
68
68
 
69
69
  test "localize Date: does not modify the options hash" do
70
70
  options = { :format => '%b', :locale => :de }
71
- assert_equal 'Mär', I18n.l(@date, options)
71
+ assert_equal 'Mär', I18n.l(@date, **options)
72
72
  assert_equal({ :format => '%b', :locale => :de }, options)
73
- assert_nothing_raised { I18n.l(@date, options.freeze) }
73
+ assert_nothing_raised { I18n.l(@date, **options.freeze) }
74
74
  end
75
75
 
76
76
  test "localize Date: given nil with default value it returns default" do
@@ -59,7 +59,7 @@ module I18n
59
59
  setup_time_proc_translations
60
60
  time = ::Time.utc(2008, 3, 1, 6, 0)
61
61
  options = { :foo => 'foo' }
62
- assert_equal I18n::Tests::Localization::Procs.inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
62
+ assert_equal I18n::Tests::Localization::Procs.inspect_args([time, options]), I18n.l(time, **options.merge(:format => :proc, :locale => :ru))
63
63
  end
64
64
 
65
65
  protected
@@ -43,9 +43,9 @@ module I18n
43
43
 
44
44
  test "lookup: does not modify the options hash" do
45
45
  options = {}
46
- assert_equal "a", I18n.t(:string, options)
46
+ assert_equal "a", I18n.t(:string, **options)
47
47
  assert_equal({}, options)
48
- assert_nothing_raised { I18n.t(:string, options.freeze) }
48
+ assert_nothing_raised { I18n.t(:string, **options.freeze) }
49
49
  end
50
50
 
51
51
  test "lookup: given an array of keys it translates all of them" do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.6.0"
4
+ VERSION = "1.7.0"
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.6.0
4
+ version: 1.7.0
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: 2019-03-03 00:00:00.000000000 Z
16
+ date: 2019-10-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -82,7 +82,7 @@ files:
82
82
  - lib/i18n/tests/pluralization.rb
83
83
  - lib/i18n/tests/procs.rb
84
84
  - lib/i18n/version.rb
85
- homepage: http://github.com/ruby-i18n/i18n
85
+ homepage: https://github.com/ruby-i18n/i18n
86
86
  licenses:
87
87
  - MIT
88
88
  metadata:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: 1.3.5
119
119
  requirements: []
120
- rubygems_version: 3.0.2
120
+ rubygems_version: 3.0.3
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: New wave Internationalization support for Ruby