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: 0704c23c3e9281b106f8ab586fbebbf0e26ece04
4
- data.tar.gz: 0be875ce8e5f47fb0de2cf1535584d5ec9a14db3
3
+ metadata.gz: 4d1a0959d1fda7cbd026bfb47d428d44072c4faf
4
+ data.tar.gz: d37b0255c177943d54b9dd3857f148a8425559e1
5
5
  SHA512:
6
- metadata.gz: a61787435c7aba311e09dc7c0a9907345893089a1daef8a01619ca1071ddf5e385b217909e197f0c9182166939737739541162bce8935726a72c2d1db8ca1227
7
- data.tar.gz: 2adae0cfdd8bf0dcce6e5678e24d3bffcae663cd67eb418d0287a25565f0df61989cda94ac58f9fc41c309eb34e23d669665e1777dd9b4d900e987a125385e2d
6
+ metadata.gz: 8b4b4e39527f47afc0035ea6a56ef8ce0a2c2ef455ce2f0c1c7ad773f2d62f0946ad0b20d997798f7afe679b976a94b8e9913507ae532ebee74d5815c862efe1
7
+ data.tar.gz: a4b34612c1a1dacf97943c5f1d2f4dee79e220cb706b3f934875cc8aa21989d61ba045a3274f0cda56e207cb4562796246fe05d52d12fd958f65e05a68bd17ce
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lost_in_translations (1.3.1)
4
+ lost_in_translations (1.3.2)
5
5
  i18n (~> 0.7)
6
6
 
7
7
  GEM
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 'Cavaleiro'
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.translate(object, field, locale)
184
- translations = #get_data_from_redis_or_yaml_file(object)
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
  ```
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module LostInTranslations
2
2
 
3
- VERSION = '1.3.1'.freeze
3
+ VERSION = '1.3.2'.freeze
4
4
 
5
5
  end
@@ -74,9 +74,28 @@ describe LostInTranslations do
74
74
  end
75
75
  end
76
76
 
77
- describe "#config.translation_data_field" do
77
+ describe "#translation_data" do
78
78
 
79
- context "when setting the 'translation_data_field' to a known method" do
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 "calling a translated field must return a translation" do
100
- I18n.with_locale(:en) do
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 'translation_data_field' to an unknown method" do
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 "calling a translated field, must raise an error" do
123
- I18n.with_locale(:en) do
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
- end
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 "calling a translated field must return a translation" do
154
- I18n.with_locale(:en) do
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
 
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  shared_examples_for "a basic usage" do
4
- it "should behave like the readme says" do
4
+ it "should behave like the readme says it does" do
5
5
  I18n.default_locale = :pt
6
6
  I18n.locale = :fr
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lost_in_translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - StreetBees Dev Team