i18n 1.0.1 → 1.1.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: 6abb11703c717406a1a4e5df13e88679656a3bb798cd0141e4ef9961fed64056
4
- data.tar.gz: 1e633332f63054b3919c887a853a1bb4348025550531bf3f499a924a1b37acf5
3
+ metadata.gz: 00ca216533d9fa4b869395ffc218a4c048b5d86c3db3b93d6cae489e7578a7a9
4
+ data.tar.gz: 805b70e0c7cc30d1c11c60ccb52d8e9e1c5693a86e57690959c182dc40005af3
5
5
  SHA512:
6
- metadata.gz: 6fe991afffcec28225b53932a1977c6c30ee6f8a79a0256380a552f25ca6d0bffd3b21452d8177529d97aac9f880e1296072804942c0b99a379ecfeb6c8ca446
7
- data.tar.gz: b8a7625539fe9e5c0c49b0a85a3bce54c1fb46e68ed4910870aee8c6f37afb589888b3ba87a6786e4364021a831619874f796a38eea6d0e6b285f67e232b3926
6
+ metadata.gz: fbe0187478522d98f7fe3ff79c71b1ebc0b34e6f3dc9bdd44803fbe7cdab192458dda74a501dc03ad9a55b6433298c53f3ebadc4132da2b00790e239ae88ebe8
7
+ data.tar.gz: b6cfa2da751b722fc379263f6dadf82b383fc8cfdddf5e7ac2722992e577361c3ee8dbe0df97b15f781ddbb971eb8f27dda034b732a1cb5d1e9a6ec31e9bd415
@@ -234,6 +234,7 @@ module I18n
234
234
  raise InvalidLocaleData.new(filename, e.inspect)
235
235
  end
236
236
  end
237
+ alias_method :load_yaml, :load_yml
237
238
 
238
239
  def translate_localization_format(locale, object, format, options)
239
240
  format.to_s.gsub(/%[aAbBpP]/) do |match|
@@ -127,6 +127,7 @@ module I18n
127
127
  if subtrees?
128
128
  super
129
129
  else
130
+ return entry unless entry.is_a?(Hash)
130
131
  key = pluralization_key(entry, count)
131
132
  entry[key]
132
133
  end
@@ -3,23 +3,14 @@
3
3
  require 'cgi'
4
4
 
5
5
  module I18n
6
- # Handles exceptions raised in the backend. All exceptions except for
7
- # MissingTranslationData exceptions are re-thrown. When a MissingTranslationData
8
- # was caught the handler returns an error message string containing the key/scope.
9
- # Note that the exception handler is not called when the option :throw was given.
10
6
  class ExceptionHandler
11
- include Module.new {
12
- def call(exception, locale, key, options)
13
- case exception
14
- when MissingTranslation
15
- exception.message
16
- when Exception
17
- raise exception
18
- else
19
- throw :exception, exception
20
- end
7
+ def call(exception, _locale, _key, _options)
8
+ if exception.is_a?(MissingTranslation)
9
+ exception.message
10
+ else
11
+ raise exception
21
12
  end
22
- }
13
+ end
23
14
  end
24
15
 
25
16
  class ArgumentError < ::ArgumentError; end
@@ -56,7 +56,7 @@ module I18n
56
56
  def initialize(*mappings)
57
57
  @map = {}
58
58
  map(mappings.pop) if mappings.last.is_a?(Hash)
59
- self.defaults = mappings.empty? ? [I18n.default_locale.to_sym] : mappings
59
+ self.defaults = mappings.empty? ? [] : mappings
60
60
  end
61
61
 
62
62
  def defaults=(defaults)
@@ -43,7 +43,7 @@ module I18n
43
43
  end
44
44
 
45
45
  test "interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
46
- assert_nothing_raised(I18n::MissingInterpolationArgument) do
46
+ assert_nothing_raised do
47
47
  assert_equal 'Barr %{foo}', interpolate(:default => '%{bar} %%{foo}', :bar => 'Barr')
48
48
  end
49
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -24,18 +24,10 @@ class I18nBackendFallbacksTranslateTest < I18n::TestCase
24
24
  assert_equal 'Interpolate %{value}', I18n.t(:interpolate)
25
25
  end
26
26
 
27
- test "returns the :en translation for a missing :de translation" do
28
- assert_equal 'Foo in :en', I18n.t(:foo, :locale => :de)
29
- end
30
-
31
27
  test "returns the :de translation for a missing :'de-DE' translation" do
32
28
  assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE')
33
29
  end
34
30
 
35
- test "returns the :en translation for translation missing in both :de and :'de-De'" do
36
- assert_equal 'Buz in :en', I18n.t(:buz, :locale => :'de-DE')
37
- end
38
-
39
31
  test "returns the :de translation for a missing :'de-DE' when :default is a String" do
40
32
  assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => "Default Bar")
41
33
  assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => "Default Bar")
@@ -106,6 +98,11 @@ class I18nBackendFallbacksTranslateTest < I18n::TestCase
106
98
  I18n.enforce_available_locales = false
107
99
  end
108
100
  end
101
+
102
+ test "returns fallback default given missing pluralization data" do
103
+ assert_equal 'default', I18n.t(:missing_bar, count: 1, default: 'default')
104
+ assert_equal 'default', I18n.t(:missing_bar, count: 0, default: 'default')
105
+ end
109
106
  end
110
107
 
111
108
  class I18nBackendFallbacksLocalizeTest < I18n::TestCase
@@ -117,18 +114,13 @@ class I18nBackendFallbacksLocalizeTest < I18n::TestCase
117
114
  super
118
115
  I18n.backend = Backend.new
119
116
  store_translations(:en, :date => { :formats => { :en => 'en' }, :day_names => %w(Sunday) })
120
- store_translations(:de, :date => { :formats => { :de => 'de' } })
117
+ store_translations(:de, :date => { :formats => { :de => 'de' }, :day_names => %w(Sunday) })
121
118
  end
122
119
 
123
120
  test "still uses an existing format as usual" do
124
121
  assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :en)
125
122
  end
126
-
127
- test "looks up and uses a fallback locale's format for a key missing in the given locale (1)" do
128
- assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :de)
129
- end
130
-
131
- test "looks up and uses a fallback locale's format for a key missing in the given locale (2)" do
123
+ test "looks up and uses a fallback locale's format for a key missing in the given locale" do
132
124
  assert_equal 'de', I18n.l(Date.today, :format => :de, :locale => :'de-DE')
133
125
  end
134
126
 
@@ -137,7 +129,7 @@ class I18nBackendFallbacksLocalizeTest < I18n::TestCase
137
129
  end
138
130
 
139
131
  test "uses a fallback locale's translation for a key missing in the given locale" do
140
- assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :de)
132
+ assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :'de-DE')
141
133
  end
142
134
  end
143
135
 
@@ -208,8 +200,8 @@ class I18nBackendFallbacksExistsTest < I18n::TestCase
208
200
  end
209
201
 
210
202
  test "exists? should return true given a key which is missing from the given locale and exists in a fallback locale" do
211
- assert_equal true, I18n.exists?(:foo, :de)
212
- assert_equal true, I18n.exists?(:foo, :'de-DE')
203
+ assert_equal true, I18n.exists?(:bar, :de)
204
+ assert_equal true, I18n.exists?(:bar, :'de-DE')
213
205
  end
214
206
 
215
207
  test "exists? should return false given a key which is missing from the given locale and all its fallback locales" do
@@ -58,4 +58,28 @@ class I18nBackendKeyValueTest < I18n::TestCase
58
58
  store_translations(:en, :bar => { :one => "One" })
59
59
  assert_equal("One", I18n.t("bar", :count => 1))
60
60
  end
61
+
62
+ test "subtrees enabled: returns localized string given missing pluralization data" do
63
+ setup_backend!(true)
64
+ assert_equal 'bar', I18n.t("foo.bar", count: 1)
65
+ end
66
+
67
+ test "subtrees disabled: returns localized string given missing pluralization data" do
68
+ setup_backend!(false)
69
+ assert_equal 'bar', I18n.t("foo.bar", count: 1)
70
+ end
71
+
72
+ test "subtrees enabled: Returns fallback default given missing pluralization data" do
73
+ setup_backend!(true)
74
+ I18n.backend.extend I18n::Backend::Fallbacks
75
+ assert_equal 'default', I18n.t(:missing_bar, count: 1, default: 'default')
76
+ assert_equal 'default', I18n.t(:missing_bar, count: 0, default: 'default')
77
+ end
78
+
79
+ test "subtrees disabled: Returns fallback default given missing pluralization data" do
80
+ setup_backend!(false)
81
+ I18n.backend.extend I18n::Backend::Fallbacks
82
+ assert_equal 'default', I18n.t(:missing_bar, count: 1, default: 'default')
83
+ assert_equal 'default', I18n.t(:missing_bar, count: 0, default: 'default')
84
+ end
61
85
  end if I18n::TestCase.key_value?
@@ -17,6 +17,10 @@ class I18nBackendSimpleTest < I18n::TestCase
17
17
  assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
18
18
  end
19
19
 
20
+ test "simple load_translations: given a YAML file name with yaml extension does not raise anything" do
21
+ assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.yaml") }
22
+ end
23
+
20
24
  test "simple load_translations: given a Ruby file name it does not raise anything" do
21
25
  assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
22
26
  end
@@ -100,4 +104,8 @@ class I18nBackendSimpleTest < I18n::TestCase
100
104
  I18n.backend.reload!
101
105
  assert_equal false, I18n.backend.initialized?
102
106
  end
107
+
108
+ test "returns localized string given missing pluralization data" do
109
+ assert_equal 'baz', I18n.t('foo.bar', count: 1)
110
+ end
103
111
  end
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
  include I18n::Locale
4
4
 
5
5
  class I18nFallbacksDefaultsTest < I18n::TestCase
6
- test "defaults reflect the I18n.default_locale if no default has been set manually" do
6
+ test "defaults to an empty array if no default has been set manually" do
7
7
  I18n.default_locale = :'en-US'
8
8
  fallbacks = Fallbacks.new
9
- assert_equal [:'en-US', :en], fallbacks.defaults
9
+ assert_equal [], fallbacks.defaults
10
10
  end
11
11
 
12
12
  test "defaults reflect a manually passed default locale if any" do
@@ -0,0 +1,3 @@
1
+ en:
2
+ foo:
3
+ bar: baz
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.0.1
4
+ version: 1.1.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: 2018-04-18 00:00:00.000000000 Z
16
+ date: 2018-08-07 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -126,6 +126,7 @@ files:
126
126
  - test/run_all.rb
127
127
  - test/test_data/locales/de.po
128
128
  - test/test_data/locales/en.rb
129
+ - test/test_data/locales/en.yaml
129
130
  - test/test_data/locales/en.yml
130
131
  - test/test_data/locales/invalid/empty.yml
131
132
  - test/test_data/locales/invalid/syntax.yml
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: 1.3.5
152
153
  requirements: []
153
154
  rubyforge_project: "[none]"
154
- rubygems_version: 2.7.4
155
+ rubygems_version: 2.7.3
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: New wave Internationalization support for Ruby