serial_translator 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3888085a84a5c13eff3a6b8159bafc2e834c855a
|
4
|
+
data.tar.gz: 96e42fdebaf9d2036b7f1de1c6d049025e3ec54e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 229673f7053e2e6e87d0727ea93361a23a1ad2eddb2c35db930ea8e5da7c8d5bb3f6bd1db6f5e7318ca67e1ef2a143993873ce164e23f8cb6e838f13ce593fff
|
7
|
+
data.tar.gz: 8f3d48e07414dbdcaa33cfeabad9f4ddae2a6900d0699e6312e096fc3c25741acc4bcc7980d13636278d0dd958b86b40abc4f7b74392d72d2e8c3ae3bfa0b8d2
|
data/lib/serial_translator.rb
CHANGED
@@ -92,7 +92,13 @@ module SerialTranslator
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def translations_for(attribute)
|
95
|
-
__send__(:"#{attribute}_translations") || {}
|
95
|
+
translations = __send__(:"#{attribute}_translations") || {}
|
96
|
+
translations.each do |locale, string|
|
97
|
+
string.singleton_class.class_eval do
|
98
|
+
define_method(:locale) { || locale }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
translations
|
96
102
|
end
|
97
103
|
|
98
104
|
def translated_into?(locale)
|
@@ -75,7 +75,7 @@ describe SerialTranslator::SerialTranslatorValidator do
|
|
75
75
|
|
76
76
|
it 'validates correctly on language change as well' do
|
77
77
|
I18n.locale = :de
|
78
|
-
example.description =
|
78
|
+
example.description = "something to make it pass valid"
|
79
79
|
example.title = 'Valid foo'
|
80
80
|
expect(example).to be_valid
|
81
81
|
|
@@ -8,6 +8,7 @@ describe SerialTranslator do
|
|
8
8
|
it 'returns the translated value in the requested locale' do
|
9
9
|
object.title_translations = { de: 'German translation', en: 'English translation' }
|
10
10
|
expect(object.title(:de)).to eq 'German translation'
|
11
|
+
expect(object.title(:de).locale).to eq :de
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'provides a boolean predicate to check the presence of a translated value' do
|
@@ -19,11 +20,13 @@ describe SerialTranslator do
|
|
19
20
|
it 'returns the origin locale value if no translation is present' do
|
20
21
|
object.title_translations = { en: 'English translation' }
|
21
22
|
expect(object.title(:de)).to eq 'English translation'
|
23
|
+
expect(object.title(:de).locale).to eq :en
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'returns the origin locale value if the translation is empty' do
|
25
27
|
object.title_translations = { de: '', en: 'English translation' }
|
26
28
|
expect(object.title(:de)).to eq 'English translation'
|
29
|
+
expect(object.title(:de).locale).to eq :en
|
27
30
|
end
|
28
31
|
|
29
32
|
it 'returns nil if no translations are there at all' do
|
@@ -35,6 +38,7 @@ describe SerialTranslator do
|
|
35
38
|
object.title_translations = { de: 'Deutsch', en: 'English' }
|
36
39
|
object.current_translation_locale = :en
|
37
40
|
expect(object.title).to eq 'English'
|
41
|
+
expect(object.title.locale).to eq :en
|
38
42
|
end
|
39
43
|
|
40
44
|
it 'does not fail even if translations were not initialized before' do
|
@@ -73,11 +77,13 @@ describe SerialTranslator do
|
|
73
77
|
it 'gets the correct translation' do
|
74
78
|
object.title_translations = { de: 'Deutsch' }
|
75
79
|
expect(object.title_de).to eq 'Deutsch'
|
80
|
+
expect(object.title_de.locale).to eq :de
|
76
81
|
end
|
77
82
|
|
78
83
|
it 'uses fallback mechanisms as well' do
|
79
84
|
object.title_translations = { en: 'English' }
|
80
85
|
expect(object.title_de).to eq 'English'
|
86
|
+
expect(object.title_de.locale).to eq :en
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serial_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace development team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.5.
|
140
|
+
rubygems_version: 2.5.1
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: Translate attribute values without additional models
|