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 +8 -8
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/traco/locale_fallbacks.rb +9 -7
- data/lib/traco/version.rb +1 -1
- data/spec/locale_fallbacks_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODYwOGJlNTZiOWNkMmU1Y2MxYTA1ZDExZTc0ZGQ0MjQ5ZjhjMjI5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmYzNmJhMjkwYjRjNmYzMThjYjk2NmFmOTYxOGNlMThkM2U0MGU0Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWY1ZDRhZmVkNDIzOTNiOThjNmU4MjIxMTViMWE5ZTI2MzU4NGI3MzgyZGYx
|
10
|
+
YmU5OWE3YTA5YmNhMWNkOWI0MjNmZjdjZWY5ZWNiN2E0YWVlYWMzZDY3MGUx
|
11
|
+
ODgxM2MwNGYzZjNkMjY1MGVhNmM3NjM4NjVjMGUyYTFjYWRhYmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzMzNzFkOGM0NjUwN2MwOGM4NDUzYTRhYTQzZDY3NWNmYzEzNmNmODFmNGQ2
|
14
|
+
ZTgzYjYwNDFiMDhiZGNiMmMyZjViNDc1YjBjMjA4NzkzYTFlMjY5MjQyNDJj
|
15
|
+
YWZiYmU2ZTIwNzE4MjFmYzJmYmYyOTlmMDJmNThjYzBlYjI3NmU=
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
data/lib/traco/version.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|