hstore_translations 0.0.1 → 0.0.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14fb5eb836cfaee82a2c483a674af4ee6e5d57ff
|
4
|
+
data.tar.gz: 41cbd94b02a4ab54d81e1e86c353fc1d5fcea928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 257518ca98e36f73d7d7ab1fde7ef9a05221fb9a20da74e9c95bf87124316ed3328c84441fb8b9b991596e3b278c464facbe4baeba405e14e22d156f0ef05741
|
7
|
+
data.tar.gz: 1305708f6b0cc321e8ccd8e281e173fa5441038018d537c9936636b93a927a95ddfe9f279f7c31543f377c904b2ce31d416e7e86a8a8094f844e6dc0083ea17a
|
@@ -4,21 +4,24 @@ module HstoreTranslations
|
|
4
4
|
|
5
5
|
def initialize(model, attribute, locale = nil)
|
6
6
|
@model, @attribute, @locale = model, attribute, locale
|
7
|
-
@locale = locale
|
7
|
+
@locale = locale
|
8
8
|
end
|
9
9
|
|
10
10
|
def value
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if @locale
|
12
|
+
try_locale(@locale)
|
13
|
+
else
|
14
|
+
fallbacks.inject(nil) do |_, locale|
|
15
|
+
value = try_locale(locale)
|
16
|
+
return value if value.present?
|
17
|
+
end
|
14
18
|
end
|
15
|
-
nil
|
16
19
|
end
|
17
20
|
|
18
21
|
private
|
19
22
|
|
20
23
|
def fallbacks
|
21
|
-
HstoreTranslations.fallbacks(@locale)
|
24
|
+
HstoreTranslations.fallbacks(@locale || HstoreTranslations.locale)
|
22
25
|
end
|
23
26
|
|
24
27
|
def try_locale(locale)
|
@@ -45,11 +45,11 @@ end
|
|
45
45
|
|
46
46
|
describe HstoreTranslations::Macro, 'generated accessors' do
|
47
47
|
before { Post.translates :title }
|
48
|
+
let(:post) { Post.new }
|
48
49
|
|
49
50
|
describe '#title=' do
|
50
|
-
let(:post) { Post.new }
|
51
51
|
before do
|
52
|
-
|
52
|
+
configure_i18n locale: :en
|
53
53
|
post.title = 'hello'
|
54
54
|
end
|
55
55
|
|
@@ -66,8 +66,8 @@ describe HstoreTranslations::Macro, 'generated accessors' do
|
|
66
66
|
let(:post) { Post.new(title_en: 'hello', title_ru: 'привет', title_es: 'hola') }
|
67
67
|
|
68
68
|
before do
|
69
|
-
|
70
|
-
|
69
|
+
configure_i18n locale: :en,
|
70
|
+
default_locale: :ru
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'is a title in current locale' do
|
@@ -100,4 +100,18 @@ describe HstoreTranslations::Macro, 'generated accessors' do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
104
|
+
describe '#title_en' do
|
105
|
+
before do
|
106
|
+
configure_i18n locale: :en,
|
107
|
+
default_locale: :ru,
|
108
|
+
available_locales: [:en, :ru]
|
109
|
+
Post.translates :title
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'does not attempt to get value with fallbacks' do
|
113
|
+
post.title_ru = 'hello'
|
114
|
+
post.title_en.should be_nil
|
115
|
+
end
|
116
|
+
end
|
103
117
|
end
|