embedded_localization 1.1.1 → 1.2.0

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: c9d4ba03a83e4b00d477de754f8543f82a1126d3
4
- data.tar.gz: fd62663a6f3f8e1bfe7d7ef0f11e185bfc5d923e
3
+ metadata.gz: 95cce5c93cc2a40e4e7334419076e952c83175ab
4
+ data.tar.gz: ebc2c99e70b2ede69842b91dc233b259fe6e2f80
5
5
  SHA512:
6
- metadata.gz: da8453448db137e3324312d8cf896909c0d697b422453a6ba7e65133b4a88bf196b0c8ff3d3429115647dfa9c2dc2260bc71d01b9d0eeb8a608b9890843b25e0
7
- data.tar.gz: f39c89fb69b5ae335bef4e11113d8386068d58f0c372ef3a9f0283b3e0e9b2d65ae38e06571b34ee4f41300bec373d3010aac858f69a9ae49da1e53a63937dfb
6
+ metadata.gz: 26548d160a1ef5802e7f60a75944fcb60abe854c7d14175f63ac7e3fa9a5f1f7cc6feb5d9dfd74a10bd79d5d1c57f1f7a48787f1725b97bf8c91d888ca76024f
7
+ data.tar.gz: 20211e8d9d86da99ce2ce539d6c4aa0a8ab2b1be8045e7a8897f73e48b31367cc9dc2af214957eb610edb3d843e536174c954d7ababb2bd2b05c23bb5200e42f
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.1
4
+ - 2.1.10
5
+ - 2.2.8
6
+ - 2.3.5
7
+ - 2.4.2
8
8
  - ruby-head
9
9
  - jruby-head
10
10
  - rbx
@@ -16,7 +16,6 @@ matrix:
16
16
  - rvm: ruby-head
17
17
  - rvm: jruby-head
18
18
  - rvm: ree
19
- - rvm: 1.8.7
20
19
  - rvm: jruby-19mode
21
20
  branches:
22
21
  only:
data/Gemfile CHANGED
@@ -6,8 +6,8 @@ gemspec
6
6
  gem 'rake'
7
7
 
8
8
  group :test do
9
- gem 'rspec', "~> 2.14"
10
- gem 'activerecord', "~> 4.0.0"
9
+ gem 'rspec', "~> 3"
10
+ gem 'activerecord', "~> 5.1"
11
11
  gem 'i18n'
12
12
  gem 'sqlite3'
13
13
  end
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Embedded Localization
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/tilo/embedded_localization.png?branch=master)](http://travis-ci.org/tilo/embedded_locallization)
3
+ [![Build Status](https://secure.travis-ci.org/tilo/embedded_localization.png?branch=master)](http://travis-ci.org/tilo/embedded_localization) [![Gem Version](https://badge.fury.io/rb/embedded_localization.svg)](http://badge.fury.io/rb/embedded_localization)
4
4
 
5
- `embedded_loalization` is compatible with Rails 3 and Rails 4, and adds model translations to ActiveRecord. `embedded_localization` is compatible with and builds on the new [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
5
+ `embedded_localization` is compatible with Rails 3 and Rails 4, and adds model translations to ActiveRecord. `embedded_localization` is compatible with and builds on the new [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
6
6
 
7
7
  `embedded_localization` is very lightweight, and allows you to transparently store translations of attributes right inside each record — no extra database tables needed to store the localization data! Make sure that your database default encoding is UTF-8 or UFT-16.
8
8
 
@@ -13,7 +13,7 @@ On top of that, you also get tools for checking into which locales an attribute
13
13
 
14
14
  ## Requirements
15
15
 
16
- * ActiveRecord > 3.0.0.rc # Tested with Rails 4.0.2, 3.2.18, 3.2.2
16
+ * ActiveRecord > 3.0.0.rc # Tested with Rails 5.1, 5,0, 4.2, 4.0.2, 3.2.18, 3.2.2
17
17
  * I18n
18
18
 
19
19
  ## Installation
@@ -47,14 +47,14 @@ In the DB migration, you just need to add the `i18n` text field:
47
47
  t.text :i18n # stores ALL the translated attributes; persisted as a Hash
48
48
 
49
49
  t.timestamps
50
- end
50
+ end
51
51
  end
52
52
  end
53
53
 
54
54
  ### Example 2
55
55
 
56
56
  Obviously you can't do SQL queries against tanslated fields which are stored in the `i18n` text field.
57
- To eliviate this problem, you can also define a normal DB attribute with the same name as your translated attribute, and it will store the value for your `I18n.default_locale`.
57
+ To eliviate this problem, you can also define a normal DB attribute with the same name as your translated attribute, and it will store the value for your `I18n.default_locale`.
58
58
 
59
59
  This way you can always do SQL queries against the values in the `I18n.default_locale`.
60
60
 
@@ -66,9 +66,9 @@ To do this, using the same model as in example 1, you can modify your migration
66
66
  t.text :i18n # stores the translated attributes; persisted as a Hash
67
67
 
68
68
  t.string :name # allows us to do SQL queries
69
-
69
+
70
70
  t.timestamps
71
- end
71
+ end
72
72
  end
73
73
  end
74
74
 
@@ -78,25 +78,25 @@ In your code you can modify the values of your translated attributes in two ways
78
78
 
79
79
  ## Using Setters / Getters
80
80
 
81
- Using the built-in getter/setter methods you can set the values for any locale directly, even though
81
+ Using the built-in getter/setter methods you can set the values for any locale directly, even though
82
82
  you are using your own locale.
83
83
 
84
84
  I18n.locale = :en
85
85
  g = Genre.first
86
- g.name = 'science fiction'
87
-
86
+ g.name = 'science fiction'
87
+
88
88
  # even though you are using the :en locale, you can still set the values for other locales:
89
-
89
+
90
90
  g.set_localized_attribute( :name, :jp, "サイエンスフィクション" )
91
91
  g.set_localized_attribute( :name, :ko, "공상 과학 소설" )
92
-
92
+
93
93
  g.name # => 'science fiction'
94
94
  g.name(:jp) # => "サイエンスフィクション"
95
95
  g.name(:ko) # => "공상 과학 소설"
96
-
96
+
97
97
  g.get_localized_attribute( :name, :jp ) # => "サイエンスフィクション"
98
98
  g.get_localized_attribute( :name, :ko ) # => "공상 과학 소설"
99
-
99
+
100
100
  ## Tweaking `I18n.locale`
101
101
 
102
102
  By manipulating the `I18n.locale`. This is what happens if you have user's with different locales entering values into a database.
@@ -106,31 +106,31 @@ By manipulating the `I18n.locale`. This is what happens if you have user's with
106
106
  I18n.locale = :en
107
107
  g = Genre.first
108
108
  g.name # => 'science fiction'
109
-
109
+
110
110
  I18n.locale = :jp
111
111
  g.name = "サイエンスフィクション"
112
-
112
+
113
113
  I18n.locale = :ko
114
114
  g.name = "공상 과학 소설"
115
115
  g.name # => "공상 과학 소설"
116
-
116
+
117
117
  I18n.locale = :jp
118
118
  g.name # => "サイエンスフィクション"
119
-
119
+
120
120
  I18n.locale = :en # MAKE SURE to switch back to your default locale if you tweak it
121
-
122
-
121
+
122
+
123
123
  ## SQL Queries against Translated Fields
124
124
 
125
125
  Old `embedded_localization` implementations < 0.2.0 had the drawback that you can not do SQL queries on translated attributes.
126
126
 
127
- To eliminate this limitation, you can now define any translated attribute as a first-class database column in your migration.
127
+ To eliminate this limitation, you can now define any translated attribute as a first-class database column in your migration.
128
128
 
129
- If you define a translated attribute as a column, `embedded_localization` will store the attribute value for I18n.default_locale in that column, so you can search for it.
129
+ If you define a translated attribute as a column, `embedded_localization` will store the attribute value for I18n.default_locale in that column, so you can search for it.
130
130
 
131
131
  After defining the column, and running the migration, you need to populate the column initially. It will auto-update every time you write while you are using I18n.default_locale .
132
132
 
133
- See also Example 2 above.
133
+ See also Example 2 above.
134
134
 
135
135
  I18n.locale = :en
136
136
  g = Genre.first
@@ -215,17 +215,17 @@ Each model instance of a class which uses `embedded_localization` will have thes
215
215
  * hash of translation coverage for a given record's attributes or a particular attribute
216
216
  * hash of missing translations for a given record's attributes or a particular attribute
217
217
  * directly setting and getting attribute values for a given locale; without having to change `I18n.locale`
218
-
218
+
219
219
  e.g.:
220
220
 
221
221
  g = Genre.where(:name => "science fiction").first
222
-
222
+
223
223
  # check if an attribute is translated:
224
224
  g.translated?(:name) # => true
225
-
225
+
226
226
  # which attributes are translated?
227
227
  g.translated_attributes # => [:description, :name]
228
-
228
+
229
229
  # check for which locales we have values: (spanning all translated fields)
230
230
  g.translated_locales # => [:en]
231
231
 
@@ -237,13 +237,13 @@ e.g.:
237
237
  # show details for which locales the attributes have values for:
238
238
  # for all attributes:
239
239
  g.translation_coverage # => {:name=>[:en], :description=>[:de]}
240
-
241
- # for a specific attribute:
240
+
241
+ # for a specific attribute:
242
242
  g.translation_coverage(:name) # => [:en]
243
243
  g.translation_coverage(:description) # => [:de]
244
244
 
245
245
  # show where translations are missing:
246
- # for all attributes:
246
+ # for all attributes:
247
247
  g.translation_missing # => {:description=>[:en], :name=>[:de]}
248
248
 
249
249
  # for a specific attribute:
@@ -251,7 +251,7 @@ e.g.:
251
251
  g.translation_missing(:description) # => [:en]
252
252
 
253
253
 
254
-
254
+
255
255
 
256
256
  #### translated_locales vs translation_coverage
257
257
 
@@ -274,30 +274,30 @@ For a new empty record, this will be empty.
274
274
  I18n.locale = :jp
275
275
  g = Genre.first
276
276
  g.name # => "サイエンスフィクション"
277
-
277
+
278
278
  g.name(:en) # => 'science fiction'
279
279
  g.name(:ko) # => "공상 과학 소설"
280
280
  g.name(:de) # => nil
281
-
281
+
282
282
  g.translated_locales # => [:en,:jp,:ko]
283
283
  g.translated_attributes # => [:name,:description]
284
284
  g.translated? # => true
285
-
285
+
286
286
  g.translation_coverage
287
287
  # => {"name"=>["en", "ko", "jp"] , "description"=>["en", "de", "fr", "ko", "jp", "es"]}
288
-
288
+
289
289
  g.translation_coverage(:name)
290
290
  # => {"name"=>["en", "ko", "jp"]}
291
-
291
+
292
292
  g.translation_missing
293
293
  # => {"name"=>["de", "fr", "es"]}
294
-
294
+
295
295
  g.translation_missing(:display)
296
296
  # => {} # this indicates that there are no missing translations for the :display attribute
297
-
297
+
298
298
  g.get_localized_attribute(:name, :de)
299
299
  # => nil
300
-
300
+
301
301
  g.set_localized_attribute(:name, :de, "Science-Fiction")
302
302
  # => "Science-Fiction"
303
303
 
@@ -311,6 +311,14 @@ If your requirements are different, my approach might not work for you. In that
311
311
 
312
312
  ## Changes
313
313
 
314
+ ### 1.2.0 (2017-11-10)
315
+ * Rails 5 compatibility
316
+ * fixing tests
317
+ * updating doc
318
+
319
+ ### 1.1.1 (2014-11-02)
320
+ * minor update
321
+
314
322
  ### 1.1.0 (2014-01-12)
315
323
  * adding more rspec tests.
316
324
  * improving documentation and README
@@ -1,3 +1,3 @@
1
1
  module EmbeddedLocalization
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -9,11 +9,10 @@ I18n.locale = :en
9
9
  describe 'model has translated field with attribute of that same name' do
10
10
  let(:movie){ Movie.new }
11
11
 
12
-
13
12
  describe "basic things that need to work" do
14
13
 
15
14
  it 'reports it translates' do
16
- Movie.translates?.should be_true
15
+ Movie.translates?.should be_truthy
17
16
  end
18
17
 
19
18
  it 'correctly reports the list of translated_attributes' do
@@ -25,12 +24,12 @@ describe 'model has translated field with attribute of that same name' do
25
24
  end
26
25
 
27
26
  it 'correcty shows the translated attribute as translated' do
28
- Movie.translated?(:title).should be_true
29
- Movie.translated?(:description).should be_true
27
+ Movie.translated?(:title).should be_truthy
28
+ Movie.translated?(:description).should be_truthy
30
29
  end
31
30
 
32
31
  it 'correcty shows not translated attribute' do
33
- Movie.translated?(:other).should be_false
32
+ Movie.translated?(:other).should be_falsy
34
33
  end
35
34
  end
36
35
 
@@ -41,7 +40,7 @@ describe 'model has translated field with attribute of that same name' do
41
40
  end
42
41
 
43
42
  it 'correctly reports translation_missing for new record' do
44
- movie.translation_missing.should be_true
43
+ movie.translation_missing.should be_truthy
45
44
  end
46
45
 
47
46
  it 'creates the accessor methods' do
@@ -153,7 +152,7 @@ describe 'model has translated field with attribute of that same name' do
153
152
 
154
153
  it 'can assign the translated field' do
155
154
  movie.title = title_en
156
- movie.save.should be_true
155
+ movie.save.should be_truthy
157
156
  movie.title.should eq title_en
158
157
  movie.title(:en).should eq title_en
159
158
  end
@@ -13,7 +13,7 @@ describe 'model has translated field without attribute of that same name' do
13
13
  describe "basic things that need to work" do
14
14
 
15
15
  it 'reports it translates' do
16
- Genre.translates?.should be_true
16
+ Genre.translates?.should be_truthy
17
17
  end
18
18
 
19
19
  it 'correctly reports the list of translated_attributes' do
@@ -25,12 +25,12 @@ describe 'model has translated field without attribute of that same name' do
25
25
  end
26
26
 
27
27
  it 'correcty shows the translated attribute as translated' do
28
- Genre.translated?(:name).should be_true
29
- Genre.translated?(:description).should be_true
28
+ Genre.translated?(:name).should be_truthy
29
+ Genre.translated?(:description).should be_truthy
30
30
  end
31
31
 
32
32
  it 'correcty shows not translated attribute' do
33
- Genre.translated?(:other).should be_false
33
+ Genre.translated?(:other).should be_falsy
34
34
  end
35
35
  end
36
36
 
@@ -41,7 +41,7 @@ describe 'model has translated field without attribute of that same name' do
41
41
  end
42
42
 
43
43
  it 'correctly reports translation_missing for new record' do
44
- genre.translation_missing.should be_true
44
+ genre.translation_missing.should be_truthy
45
45
  end
46
46
 
47
47
  it 'creates the accessor methods' do
@@ -151,7 +151,7 @@ describe 'model has translated field without attribute of that same name' do
151
151
 
152
152
  it 'can assign the translated field' do
153
153
  genre.name = genre_name_en
154
- genre.save.should be_true
154
+ genre.save.should be_truthy
155
155
  genre.name.should eq genre_name_en
156
156
  genre.name(:en).should eq genre_name_en
157
157
  end
@@ -13,8 +13,17 @@ load File.dirname(__FILE__) + '/schema.rb'
13
13
  require File.dirname(__FILE__) + '/models.rb'
14
14
 
15
15
 
16
+ I18n.enforce_available_locales = false
17
+ I18n.config.available_locales = [:ru,:jp,:ko,:fr,:en,:de]
18
+
16
19
  RSpec.configure do |config|
17
- config.treat_symbols_as_metadata_keys_with_true_values = true
18
- config.filter_run :focus => true
20
+ config.expect_with :rspec do |expectations|
21
+ expectations.syntax = :should
22
+ end
23
+ config.mock_with :rspec do |mocks|
24
+ mocks.syntax = :should
25
+ end
26
+
27
+ config.filter_run_including :focus => true
19
28
  config.run_all_when_everything_filtered = true
20
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embedded_localization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilo Sloboda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-02 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project: "[none]"
118
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.6.13
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: 'Rails I18n: library for embedded ActiveRecord 3 model/data translation'