lost_in_translations 1.3.1 → 1.3.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: 4d1a0959d1fda7cbd026bfb47d428d44072c4faf
|
4
|
+
data.tar.gz: d37b0255c177943d54b9dd3857f148a8425559e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b4b4e39527f47afc0035ea6a56ef8ce0a2c2ef455ce2f0c1c7ad773f2d62f0946ad0b20d997798f7afe679b976a94b8e9913507ae532ebee74d5815c862efe1
|
7
|
+
data.tar.gz: a4b34612c1a1dacf97943c5f1d2f4dee79e220cb706b3f934875cc8aa21989d61ba045a3274f0cda56e207cb4562796246fe05d52d12fd958f65e05a68bd17ce
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -124,7 +124,7 @@ I18n.locale = :fr
|
|
124
124
|
|
125
125
|
@user.first_name # returns 'Jean'
|
126
126
|
@user.last_name # returns 'Neve'
|
127
|
-
@user.title # returns
|
127
|
+
@user.title # returns nil
|
128
128
|
```
|
129
129
|
|
130
130
|
## 3) Configuration
|
@@ -180,10 +180,8 @@ User.find(1).first_name # returns 'Jean'
|
|
180
180
|
### 3.3) Custom translation mechanism
|
181
181
|
```ruby
|
182
182
|
class MyTranslator < Translator::Base
|
183
|
-
def self.
|
184
|
-
|
185
|
-
|
186
|
-
(translations[locale] || {})[field]
|
183
|
+
def self.translation_data(object)
|
184
|
+
# get_data_from_redis_or_yaml_file(object)
|
187
185
|
end
|
188
186
|
end
|
189
187
|
```
|
data/lib/lost_in_translations.rb
CHANGED
@@ -28,6 +28,10 @@ module LostInTranslations
|
|
28
28
|
config.translator.assign_translation(*args)
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.translation_data(object)
|
32
|
+
config.translator.translation_data(object)
|
33
|
+
end
|
34
|
+
|
31
35
|
def self.define_translation_methods(object, *fields)
|
32
36
|
fields.each do |field|
|
33
37
|
define_dynamic_translation_method(object, field)
|
@@ -74,9 +74,28 @@ describe LostInTranslations do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe "#
|
77
|
+
describe "#translation_data" do
|
78
78
|
|
79
|
-
context "when
|
79
|
+
context "when the object.translation_data is nil" do
|
80
|
+
before do
|
81
|
+
@user_class = Struct.new(:first_name, :last_name) do
|
82
|
+
include LostInTranslations
|
83
|
+
|
84
|
+
translate :first_name
|
85
|
+
|
86
|
+
attr_accessor :translation_data
|
87
|
+
end
|
88
|
+
|
89
|
+
@user = @user_class.new('joao', 'neve')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return an empty Hash" do
|
93
|
+
expect(LostInTranslations.translation_data(@user)).to eq({})
|
94
|
+
expect(@user.translation_data).to eq({})
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when setting the #config.translation_data_field to a known method" do
|
80
99
|
before do
|
81
100
|
LostInTranslations.configure do |config|
|
82
101
|
config.translation_data_field = 'translation_json'
|
@@ -96,14 +115,12 @@ describe LostInTranslations do
|
|
96
115
|
end
|
97
116
|
after { LostInTranslations.config.translation_data_field = 'translation_data' }
|
98
117
|
|
99
|
-
it "
|
100
|
-
|
101
|
-
expect(@user.first_name).to eq 'Jon'
|
102
|
-
end
|
118
|
+
it "should return the known method results" do
|
119
|
+
expect(LostInTranslations.translation_data(@user)).to eq({ en: { first_name: 'Jon', last_name: 'Snow' } })
|
103
120
|
end
|
104
121
|
end
|
105
122
|
|
106
|
-
context "when setting the
|
123
|
+
context "when setting the #config.translation_data_field to an unknown method" do
|
107
124
|
before do
|
108
125
|
LostInTranslations.configure do |config|
|
109
126
|
config.translation_data_field = 'translation_json'
|
@@ -119,18 +136,12 @@ describe LostInTranslations do
|
|
119
136
|
end
|
120
137
|
after { LostInTranslations.config.translation_data_field = 'translation_data' }
|
121
138
|
|
122
|
-
it "
|
123
|
-
|
124
|
-
expect { @user.first_name }.to raise_error(NotImplementedError)
|
125
|
-
end
|
139
|
+
it "should raise an error" do
|
140
|
+
expect { LostInTranslations.translation_data(@user) }.to raise_error(NotImplementedError)
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
129
|
-
|
130
|
-
|
131
|
-
describe "#config.translator" do
|
132
|
-
|
133
|
-
context "changing the source of the translation_data" do
|
144
|
+
context "when changing the #config.translator" do
|
134
145
|
before do
|
135
146
|
LostInTranslations.configure do |config|
|
136
147
|
config.translator = Class.new(LostInTranslations::Translator::Base) do
|
@@ -150,10 +161,8 @@ describe LostInTranslations do
|
|
150
161
|
end
|
151
162
|
after { LostInTranslations.config.translator = LostInTranslations::Translator::Base }
|
152
163
|
|
153
|
-
it "
|
154
|
-
|
155
|
-
expect(@user.first_name).to eq 'Jon'
|
156
|
-
end
|
164
|
+
it "should return the known method results" do
|
165
|
+
expect(LostInTranslations.translation_data(@user)).to eq({ en: { first_name: 'Jon', last_name: 'Snow' } })
|
157
166
|
end
|
158
167
|
end
|
159
168
|
|