i18n 1.13.0 → 1.14.1

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: e85066f2cf6bbf170ff946391c6037d0335e5314d0c1e0723e980d5ee7df7af0
4
- data.tar.gz: 2a4629aa0644c2a6e8cc5d175d4912b5f5cd4abc066dd5ee196270b7a3eadd08
3
+ metadata.gz: 692bec57675f1d97cdd0dff4a7b444e1777ba2f360dc3cf7162d5a98e45ab0a5
4
+ data.tar.gz: 954df8c7788ce253f730e4bf6911373198b26c24c2274113b2e12b6d6527b486
5
5
  SHA512:
6
- metadata.gz: '01326189eb7b675594bd63c802ae9470135e9aab222de4df1429c99c585b9b59b172ed62386c03b82fd45c862bbb42484dc89e0289c83970315f9a5fa03ba91c'
7
- data.tar.gz: 290489ae277759fe65197e65d6486b7cca67605c2c98197a472c91bb2496d9db168dfd2082706b87f6f806051827b8df12cc0037258f3bf10d5f74a9ddb9f575
6
+ metadata.gz: 26ebf6f4edea8d2a6cf511496bcad2c0e50323c44263c4d27e44f12860f9e4e35e093514bb1fb3cd9925591b5e3db62917af79ee2710b4cc759735dd1ff4d538
7
+ data.tar.gz: 1764731c2157cddb200a8dec9286248f7fac4e8a23548305aa09e70b5591d924748179c9534bb46cd6d7d892987963566d95e20854d5928b51a0fbad76dded3b
@@ -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
@@ -98,7 +98,7 @@ module I18n
98
98
  # Parse the load path and extract all locales.
99
99
  def available_locales
100
100
  if lazy_load?
101
- I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }
101
+ I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }.uniq
102
102
  else
103
103
  super
104
104
  end
@@ -47,7 +47,7 @@ module I18n
47
47
 
48
48
  class MissingTranslation < ArgumentError
49
49
  module Base
50
- PERMITTED_KEYS = [:scope].freeze
50
+ PERMITTED_KEYS = [:scope, :default].freeze
51
51
 
52
52
  attr_reader :locale, :key, :options
53
53
 
@@ -63,8 +63,18 @@ module I18n
63
63
  end
64
64
 
65
65
  def message
66
- "translation missing: #{keys.join('.')}"
66
+ if (default = options[:default]).is_a?(Array) && default.any?
67
+ other_options = ([key, *default]).map { |k| normalized_option(k).prepend('- ') }.join("\n")
68
+ "Translation missing. Options considered were:\n#{other_options}"
69
+ else
70
+ "Translation missing: #{keys.join('.')}"
71
+ end
72
+ end
73
+
74
+ def normalized_option(key)
75
+ I18n.normalize_keys(locale, key, options[:scope]).join('.')
67
76
  end
77
+
68
78
  alias :to_s :message
69
79
 
70
80
  def to_exception
@@ -64,7 +64,7 @@ module I18n
64
64
  end
65
65
 
66
66
  test "localize Date: given missing translations it returns the correct error message" do
67
- assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
67
+ assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
68
68
  end
69
69
 
70
70
  test "localize Date: given an unknown format it does not fail" do
@@ -60,7 +60,7 @@ module I18n
60
60
  end
61
61
 
62
62
  test "localize DateTime: given missing translations it returns the correct error message" do
63
- assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
63
+ assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
64
64
  end
65
65
 
66
66
  test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
@@ -61,7 +61,7 @@ module I18n
61
61
  end
62
62
 
63
63
  test "localize Time: given missing translations it returns the correct error message" do
64
- assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
64
+ assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
65
65
  end
66
66
 
67
67
  test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
@@ -30,7 +30,7 @@ module I18n
30
30
  end
31
31
 
32
32
  test "lookup: given a missing key, no default and no raise option it returns an error message" do
33
- assert_equal "translation missing: en.missing", I18n.t(:missing)
33
+ assert_equal "Translation missing: en.missing", I18n.t(:missing)
34
34
  end
35
35
 
36
36
  test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" 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.13.0"
4
+ VERSION = "1.14.1"
5
5
  end
data/lib/i18n.rb CHANGED
@@ -331,11 +331,12 @@ module I18n
331
331
  # keys are Symbols.
332
332
  def normalize_keys(locale, key, scope, separator = nil)
333
333
  separator ||= I18n.default_separator
334
- locale = locale.to_sym if locale
335
334
 
336
- result = [locale]
337
- result.concat(normalize_key(scope, separator)) if scope
338
- result.concat(normalize_key(key, separator))
335
+ [
336
+ *normalize_key(locale, separator),
337
+ *normalize_key(scope, separator),
338
+ *normalize_key(key, separator)
339
+ ]
339
340
  end
340
341
 
341
342
  # Returns true when the passed locale, which can be either a String or a
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.13.0
4
+ version: 1.14.1
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-04-26 00:00:00.000000000 Z
16
+ date: 2023-06-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby