traco 3.1.6 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzZlZTA3YTcxYTNiNDA3ZmQ3MTdhMzE5ZGQxNzA1Yzg4YmFhMjI5Mg==
4
+ ODYwOGJlNTZiOWNkMmU1Y2MxYTA1ZDExZTc0ZGQ0MjQ5ZjhjMjI5ZA==
5
5
  data.tar.gz: !binary |-
6
- OTQ3MzczNzVmZDI4ZWMwYjBhOGY0NjMyZmU4MWE1N2UyN2RhMTZkMA==
6
+ MmYzNmJhMjkwYjRjNmYzMThjYjk2NmFmOTYxOGNlMThkM2U0MGU0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjkwNjFmOWJiNmM2ZDg1MzI3ZGNlNDBkMzU3ZTIwYWRiN2NkNjJmMzFjMjQ3
10
- ZGNlOGIyNzA1MzM5OGQ4YzBlN2M2ZmFlZjE5ZTg5ZjgyNzY5YmMxZDQ4MDcz
11
- MTBiYTAyOGMyYjNmOWVkNzU0Yzk0MDU4NGE2NDY3ZjZhYmQxMjQ=
9
+ OWY1ZDRhZmVkNDIzOTNiOThjNmU4MjIxMTViMWE5ZTI2MzU4NGI3MzgyZGYx
10
+ YmU5OWE3YTA5YmNhMWNkOWI0MjNmZjdjZWY5ZWNiN2E0YWVlYWMzZDY3MGUx
11
+ ODgxM2MwNGYzZjNkMjY1MGVhNmM3NjM4NjVjMGUyYTFjYWRhYmM=
12
12
  data.tar.gz: !binary |-
13
- MjdkMWE2YzM0NzcxYjZkYjkzNzZiYWVmZTMyMGUxMjVmNzMxYjAyZjVmYzBi
14
- YmRhMDY3YWM5OTI3MzdmNDBhNTVjZjVkMDBmZTQ4ZjE5OWVhMjQ0ZjhkYTk3
15
- OWE1MjBlZWM4ZWYxNzMyYWJjNzE5Njk4OWMxNDRkYTU2Nzg3YTA=
13
+ NzMzNzFkOGM0NjUwN2MwOGM4NDUzYTRhYTQzZDY3NWNmYzEzNmNmODFmNGQ2
14
+ ZTgzYjYwNDFiMDhiZGNiMmMyZjViNDc1YjBjMjA4NzkzYTFlMjY5MjQyNDJj
15
+ YWZiYmU2ZTIwNzE4MjFmYzJmYmYyOTlmMDJmNThjYzBlYjI3NmU=
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.2.0
4
+
5
+ * Introduce e.g. `fallback: [:sv]` to explicitly specify fallbacks.
6
+
3
7
  ## 3.1.6
4
8
 
5
9
  Make [license (MIT)](LICENSE.txt) easier to autodetect.
data/README.md CHANGED
@@ -94,6 +94,8 @@ You can specify e.g. `translates :title, fallback: false` to never fall back and
94
94
 
95
95
  You can specify e.g. `translates :title, fallback: :any` to fall back first to the default locale, then to any other locale.
96
96
 
97
+ You can specify e.g. `translates :title, fallback: [:sv]` to explicitly declare fallbacks as an array of any length.
98
+
97
99
  You can override the default fallback strategy with a parameter passed to the reader: `post.title(fallback: :any)`.
98
100
 
99
101
  If you need to declare the default locale fallback, do `post.title(fallback: :default)`.
@@ -13,7 +13,9 @@ module Traco
13
13
  private :fallback_option
14
14
 
15
15
  def initialize(fallback_option)
16
- @fallback_option = validate_option(fallback_option)
16
+ validate_option(fallback_option)
17
+
18
+ @fallback_option = fallback_option
17
19
  @default_locale = I18n.default_locale
18
20
  @available_locales = I18n.available_locales.sort
19
21
  end
@@ -24,6 +26,7 @@ module Traco
24
26
  when ANY_FALLBACK then [ current_locale, @default_locale, *@available_locales ].uniq
25
27
  when NO_FALLBACK then [ current_locale ]
26
28
  when DEFAULT_FIRST_FALLBACK then [ @default_locale, *@available_locales ].uniq
29
+ when Array then fallback_option
27
30
  else raise "Unknown fallback." # Should never get here.
28
31
  end
29
32
  end
@@ -31,12 +34,11 @@ module Traco
31
34
  private
32
35
 
33
36
  def validate_option(fallback_option)
34
- if OPTIONS.include?(fallback_option)
35
- fallback_option
36
- else
37
- valids = OPTIONS.map(&:inspect).join(", ")
38
- raise ArgumentError.new("Unsupported fallback: #{fallback_option.inspect} (expected one of #{valids})")
39
- end
37
+ return if OPTIONS.include?(fallback_option)
38
+ return if fallback_option.is_a?(Array)
39
+
40
+ valids = OPTIONS.map(&:inspect).join(", ")
41
+ raise ArgumentError.new("Unsupported fallback: #{fallback_option.inspect} (expected one of #{valids}, or an array)")
40
42
  end
41
43
  end
42
44
  end
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "3.1.6"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -35,6 +35,13 @@ describe Traco::LocaleFallbacks do
35
35
  end
36
36
  end
37
37
 
38
+ context "with an explicit list of locales" do
39
+ it "returns only those locales" do
40
+ subject = Traco::LocaleFallbacks.new([ :en ])
41
+ expect(subject[:sv]).to eq [ :en ]
42
+ end
43
+ end
44
+
38
45
  context "with the ':default_first' option" do
39
46
  it "returns default locale, then remaining available locales alphabetically" do
40
47
  I18n.default_locale = :uk
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord