globalize 5.0.1 → 5.1.0

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +19 -5
  4. data/Gemfile.lock +101 -55
  5. data/{readme.md → README.md} +128 -35
  6. data/Rakefile +33 -0
  7. data/lib/globalize/active_record/act_macro.rb +29 -3
  8. data/lib/globalize/active_record/adapter.rb +10 -11
  9. data/lib/globalize/active_record/adapter_dirty.rb +54 -0
  10. data/lib/globalize/active_record/class_methods.rb +19 -6
  11. data/lib/globalize/active_record/exceptions.rb +1 -7
  12. data/lib/globalize/active_record/instance_methods.rb +55 -35
  13. data/lib/globalize/active_record/migration.rb +57 -30
  14. data/lib/globalize/active_record/query_methods.rb +42 -17
  15. data/lib/globalize/active_record.rb +1 -0
  16. data/lib/globalize/version.rb +1 -1
  17. data/lib/globalize.rb +12 -6
  18. data/lib/patches/active_record/persistence.rb +6 -15
  19. data/lib/patches/active_record/query_method.rb +2 -34
  20. data/lib/patches/active_record/rails4/query_method.rb +35 -0
  21. data/lib/patches/active_record/rails4/serialization.rb +22 -0
  22. data/lib/patches/active_record/rails4/uniqueness_validator.rb +42 -0
  23. data/lib/patches/active_record/rails5/uniqueness_validator.rb +47 -0
  24. data/lib/patches/active_record/rails5_1/serialization.rb +22 -0
  25. data/lib/patches/active_record/rails5_1/uniqueness_validator.rb +45 -0
  26. data/lib/patches/active_record/relation.rb +12 -0
  27. data/lib/patches/active_record/serialization.rb +5 -24
  28. data/lib/patches/active_record/uniqueness_validator.rb +7 -39
  29. data/lib/patches/active_record/xml_attribute_serializer.rb +19 -9
  30. metadata +28 -22
  31. data/globalize.gemspec +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f79ee6b19f357cae4c848d662d6f081a6375b8c
4
- data.tar.gz: 1f4fe986e59139c19acd2c2eac58b7598213ed85
3
+ metadata.gz: 57f25eaab88304fdb368cbbf71aba41413e20a49
4
+ data.tar.gz: 074e1bb69520bbf7b7dd658beaede38b8f58fcbc
5
5
  SHA512:
6
- metadata.gz: 5f9894c0da31c4734117700845576c612e24a9c4575fc19370c87f788837ea6bf0968fe46c51d094c9a75d0fc39d1c7204b2b581716a5663a5a82ef901ae12de
7
- data.tar.gz: c6ee550b86c3cec2e43443d11791b88a03c0d541cb1791a1b3aed249f664297ca96b0721823322c78ba8a869e4b82508727b70889d8c47b4a83f86caa6505a64
6
+ metadata.gz: 6793d5894ce36c34d65b8c59b0c26d12f268cfe27a0fdcba0bde632df9c0418af1c975c71ef14f56bcbcc0749b726f8d751c2e02b64e173b457e3a240527dfa7
7
+ data.tar.gz: b718eed39f3683df1faa47828c5535b8c50466b6fed9c15f17cd670e6597c7cbc749db725cdbeb7c711044b1a25b92d1c9042d90cfa6d71b424adbef7ffe9eec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Globalize Changelog
2
2
 
3
+ ## 5.1.0 (unreleased)
4
+
5
+ * Replaced `after_` callbacks with `before_` callbacks and set `autosave: true` by default. [#341](https://github.com/globalize/globalize/pull/341) by [Andrew Volozhanin](https://github.com/scarfacedeb)
6
+ * Add [RequestStore](https://github.com/steveklabnik/request_store) to make Globalize thread-safe again [#420](https://github.com/globalize/globalize/pull/420)
7
+ * Join the translations table when ordering by translated attributes (https://github.com/globalize/globalize/pull/447). (thanks [Thomas Maas](https://github.com/thomasmaas) & [Michal Cichra](https://github.com/mikz)).
8
+ * Add `unique` to `with_translation` to prevent duplicates if fallbacks are defined and the queried locale is not the fallback language. [#489](https://github.com/globalize/globalize/pull/489) by [krisdigital](https://github.com/krisdigital)
9
+
3
10
  ## 5.0.1 (2015-02-15)
4
11
 
5
12
  * Don't touch table when model is loaded. [#412](https://github.com/globalize/globalize/pull/412)
@@ -74,7 +81,12 @@
74
81
 
75
82
  * Backport scope support on uniqueness validation from 4.0, drop support for ActiveRecord < 3.1, fixes [#324](https://github.com/globalize/globalize/issues/324).
76
83
 
84
+ ## 3.0.5 (2015-04-24)
85
+
86
+ * Now working properly with the squeel library. (thanks [Toru Mori](https://github.com/torumori)). See [#437](https://github.com/globalize/globalize/pull/437)
87
+
77
88
  ## 3.0.4 (2014-01-08)
89
+
78
90
  * Extract all versioning-related code to separate [globalize-versioning](https://github.com/globalize/globalize-versioning) gem.
79
91
 
80
92
  ## 3.0.3 (2013-12-26)
data/Gemfile CHANGED
@@ -1,12 +1,26 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ gem "pry"
6
+
7
+ eval File.read(File.expand_path("../gemfiles/.gemfile.database-config.rb", __FILE__))
8
+
5
9
  platforms :rbx do
6
- gem 'rubysl', '~> 2.0'
10
+ gem "rubysl", "~> 2.0"
11
+ gem "rubinius-developer_tools"
7
12
  end
8
13
 
9
- group :test do
10
- gem 'pry'
11
- gem 'pry-nav'
14
+ platforms :jruby do
15
+ if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
16
+ gem 'activerecord-jdbcsqlite3-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
17
+ end
18
+
19
+ if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
20
+ gem 'activerecord-jdbcmysql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
21
+ end
22
+
23
+ if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
24
+ gem 'activerecord-jdbcpostgresql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
25
+ end
12
26
  end
data/Gemfile.lock CHANGED
@@ -1,52 +1,85 @@
1
+ GIT
2
+ remote: https://github.com/jruby/activerecord-jdbc-adapter
3
+ revision: 4ae8a3c4d4b00d1c33ef6b9099f63a3f78da21ad
4
+ specs:
5
+ activerecord-jdbc-adapter (51.0)
6
+ activerecord (~> 5.1.0)
7
+ activerecord-jdbcmysql-adapter (51.0)
8
+ activerecord-jdbc-adapter (~> 51.0)
9
+ jdbc-mysql (~> 5.1.36)
10
+ activerecord-jdbcpostgresql-adapter (51.0)
11
+ activerecord-jdbc-adapter (~> 51.0)
12
+ jdbc-postgres (>= 9.4, < 43)
13
+ activerecord-jdbcsqlite3-adapter (51.0)
14
+ activerecord-jdbc-adapter (~> 51.0)
15
+ jdbc-sqlite3 (~> 3.8, < 3.30)
16
+ jdbc-mysql (5.1.44)
17
+ jdbc-postgres (42.1.4)
18
+ jdbc-sqlite3 (3.20.1)
19
+
1
20
  PATH
2
21
  remote: .
3
22
  specs:
4
- globalize (5.0.1)
5
- activemodel (>= 4.2.0, < 4.3)
6
- activerecord (>= 4.2.0, < 4.3)
23
+ globalize (5.1.0)
24
+ activemodel (>= 4.2, < 5.2)
25
+ activerecord (>= 4.2, < 5.2)
26
+ request_store (~> 1.0)
7
27
 
8
28
  GEM
9
29
  remote: https://rubygems.org/
10
30
  specs:
11
- activemodel (4.2.0)
12
- activesupport (= 4.2.0)
13
- builder (~> 3.1)
14
- activerecord (4.2.0)
15
- activemodel (= 4.2.0)
16
- activesupport (= 4.2.0)
17
- arel (~> 6.0)
18
- activesupport (4.2.0)
31
+ activemodel (5.1.4)
32
+ activesupport (= 5.1.4)
33
+ activerecord (5.1.4)
34
+ activemodel (= 5.1.4)
35
+ activesupport (= 5.1.4)
36
+ arel (~> 8.0)
37
+ activesupport (5.1.4)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
39
  i18n (~> 0.7)
20
- json (~> 1.7, >= 1.7.7)
21
40
  minitest (~> 5.1)
22
- thread_safe (~> 0.3, >= 0.3.4)
23
41
  tzinfo (~> 1.1)
24
- ansi (1.4.3)
25
- arel (6.0.0)
26
- builder (3.2.2)
27
- coderay (1.1.0)
28
- database_cleaner (1.4.0)
42
+ ansi (1.5.0)
43
+ arel (8.0.0)
44
+ builder (3.2.3)
45
+ coderay (1.1.2)
46
+ concurrent-ruby (1.0.5)
47
+ concurrent-ruby (1.0.5-java)
48
+ database_cleaner (1.6.2)
49
+ ffi (1.9.18-java)
29
50
  ffi2-generators (0.1.1)
30
- i18n (0.7.0)
31
- json (1.8.2)
32
- method_source (0.8.2)
33
- minitest (5.5.1)
34
- minitest-reporters (1.0.8)
51
+ i18n (0.9.1)
52
+ concurrent-ruby (~> 1.0)
53
+ method_source (0.9.0)
54
+ minitest (5.11.1)
55
+ minitest-reporters (1.1.19)
35
56
  ansi
36
57
  builder
37
58
  minitest (>= 5.0)
38
59
  ruby-progressbar
39
- pry (0.10.1)
60
+ mysql2 (0.4.10)
61
+ pg (1.0.0)
62
+ pry (0.11.3)
63
+ coderay (~> 1.1.0)
64
+ method_source (~> 0.9.0)
65
+ pry (0.11.3-java)
40
66
  coderay (~> 1.1.0)
41
- method_source (~> 0.8.1)
42
- slop (~> 3.4)
43
- pry-nav (0.2.4)
44
- pry (>= 0.9.10, < 0.11.0)
45
- rake (10.4.2)
46
- rb-readline (0.5.2)
47
- rdoc (4.2.0)
48
- ruby-progressbar (1.7.1)
49
- rubysl (2.1.0)
67
+ method_source (~> 0.9.0)
68
+ spoon (~> 0.0)
69
+ rack (2.0.3)
70
+ rake (12.3.0)
71
+ rdoc (6.0.1)
72
+ request_store (1.4.0)
73
+ rack (>= 1.4)
74
+ rubinius-coverage (2.1)
75
+ rubinius-debugger (2.6)
76
+ rubinius-developer_tools (2.0.0)
77
+ rubinius-coverage (~> 2.0)
78
+ rubinius-debugger (~> 2.0)
79
+ rubinius-profiler (~> 2.0)
80
+ rubinius-profiler (2.1)
81
+ ruby-progressbar (1.9.0)
82
+ rubysl (2.2.0)
50
83
  rubysl-abbrev (~> 2.0)
51
84
  rubysl-base64 (~> 2.0)
52
85
  rubysl-benchmark (~> 2.0)
@@ -131,6 +164,7 @@ GEM
131
164
  rubysl-tmpdir (~> 2.0)
132
165
  rubysl-tsort (~> 2.0)
133
166
  rubysl-un (~> 2.0)
167
+ rubysl-unicode_normalize (~> 2.0)
134
168
  rubysl-uri (~> 2.0)
135
169
  rubysl-weakref (~> 2.0)
136
170
  rubysl-webrick (~> 2.0)
@@ -142,17 +176,17 @@ GEM
142
176
  rubysl-benchmark (2.0.1)
143
177
  rubysl-bigdecimal (2.0.2)
144
178
  rubysl-cgi (2.0.1)
145
- rubysl-cgi-session (2.0.1)
179
+ rubysl-cgi-session (2.1.0)
146
180
  rubysl-cmath (2.0.0)
147
181
  rubysl-complex (2.0.0)
148
182
  rubysl-continuation (2.0.0)
149
- rubysl-coverage (2.0.3)
183
+ rubysl-coverage (2.1)
150
184
  rubysl-csv (2.0.2)
151
185
  rubysl-english (~> 2.0)
152
186
  rubysl-curses (2.0.1)
153
- rubysl-date (2.0.8)
187
+ rubysl-date (2.0.9)
154
188
  rubysl-delegate (2.0.1)
155
- rubysl-digest (2.0.3)
189
+ rubysl-digest (2.0.8)
156
190
  rubysl-drb (2.0.1)
157
191
  rubysl-e2mmap (2.0.0)
158
192
  rubysl-english (2.0.0)
@@ -175,8 +209,7 @@ GEM
175
209
  rubysl-io-nonblock (2.0.0)
176
210
  rubysl-io-wait (2.0.0)
177
211
  rubysl-ipaddr (2.0.0)
178
- rubysl-irb (2.1.0)
179
- rb-readline (~> 0.5)
212
+ rubysl-irb (2.1.1)
180
213
  rubysl-e2mmap (~> 2.0)
181
214
  rubysl-mathn (~> 2.0)
182
215
  rubysl-thread (~> 2.0)
@@ -184,10 +217,10 @@ GEM
184
217
  rubysl-mathn (2.0.0)
185
218
  rubysl-matrix (2.1.0)
186
219
  rubysl-e2mmap (~> 2.0)
187
- rubysl-mkmf (2.0.1)
220
+ rubysl-mkmf (2.1)
188
221
  rubysl-fileutils (~> 2.0)
189
222
  rubysl-shellwords (~> 2.0)
190
- rubysl-monitor (2.0.0)
223
+ rubysl-monitor (2.1)
191
224
  rubysl-mutex_m (2.0.0)
192
225
  rubysl-net-ftp (2.0.1)
193
226
  rubysl-net-http (2.0.4)
@@ -203,19 +236,19 @@ GEM
203
236
  rubysl-observer (2.0.0)
204
237
  rubysl-open-uri (2.0.0)
205
238
  rubysl-open3 (2.0.0)
206
- rubysl-openssl (2.2.1)
239
+ rubysl-openssl (2.9)
207
240
  rubysl-optparse (2.0.1)
208
241
  rubysl-shellwords (~> 2.0)
209
- rubysl-ostruct (2.0.4)
210
- rubysl-pathname (2.1.0)
242
+ rubysl-ostruct (2.1.0)
243
+ rubysl-pathname (2.3)
211
244
  rubysl-prettyprint (2.0.3)
212
245
  rubysl-prime (2.0.1)
213
246
  rubysl-profile (2.0.0)
214
- rubysl-profiler (2.0.1)
247
+ rubysl-profiler (2.1)
215
248
  rubysl-pstore (2.0.0)
216
249
  rubysl-pty (2.0.3)
217
250
  rubysl-rational (2.0.1)
218
- rubysl-resolv (2.1.0)
251
+ rubysl-resolv (2.1.2)
219
252
  rubysl-rexml (2.0.4)
220
253
  rubysl-rinda (2.0.1)
221
254
  rubysl-rss (2.0.0)
@@ -224,14 +257,15 @@ GEM
224
257
  rubysl-set (2.0.1)
225
258
  rubysl-shellwords (2.0.0)
226
259
  rubysl-singleton (2.0.0)
227
- rubysl-socket (2.0.1)
228
- rubysl-stringio (2.0.0)
260
+ rubysl-socket (2.2.1)
261
+ rubysl-fcntl (~> 2.0)
262
+ rubysl-stringio (2.2)
229
263
  rubysl-strscan (2.0.0)
230
264
  rubysl-sync (2.0.0)
231
265
  rubysl-syslog (2.1.0)
232
266
  ffi2-generators (~> 0.1)
233
267
  rubysl-tempfile (2.0.1)
234
- rubysl-thread (2.0.2)
268
+ rubysl-thread (2.1)
235
269
  rubysl-thwait (2.0.0)
236
270
  rubysl-time (2.0.3)
237
271
  rubysl-timeout (2.0.0)
@@ -240,29 +274,41 @@ GEM
240
274
  rubysl-un (2.0.0)
241
275
  rubysl-fileutils (~> 2.0)
242
276
  rubysl-optparse (~> 2.0)
277
+ rubysl-unicode_normalize (2.0)
243
278
  rubysl-uri (2.0.0)
244
279
  rubysl-weakref (2.0.0)
245
280
  rubysl-webrick (2.0.0)
246
281
  rubysl-xmlrpc (2.0.0)
247
282
  rubysl-yaml (2.1.0)
248
283
  rubysl-zlib (2.0.1)
249
- slop (3.6.0)
250
- sqlite3 (1.3.10)
251
- thread_safe (0.3.4)
252
- tzinfo (1.2.2)
284
+ spoon (0.0.6)
285
+ ffi
286
+ sqlite3 (1.3.13)
287
+ thread_safe (0.3.6)
288
+ thread_safe (0.3.6-java)
289
+ tzinfo (1.2.4)
253
290
  thread_safe (~> 0.1)
254
291
 
255
292
  PLATFORMS
293
+ java
256
294
  ruby
257
295
 
258
296
  DEPENDENCIES
259
- database_cleaner (~> 1.4.0)
297
+ activerecord-jdbcmysql-adapter!
298
+ activerecord-jdbcpostgresql-adapter!
299
+ activerecord-jdbcsqlite3-adapter!
300
+ database_cleaner
260
301
  globalize!
261
302
  minitest
262
303
  minitest-reporters
304
+ mysql2
305
+ pg
263
306
  pry
264
- pry-nav
265
307
  rake
266
308
  rdoc
309
+ rubinius-developer_tools
267
310
  rubysl (~> 2.0)
268
311
  sqlite3
312
+
313
+ BUNDLED WITH
314
+ 1.16.1
@@ -9,6 +9,8 @@ You can chat with us using Gitter:
9
9
  Globalize builds on the [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
10
10
  to add model translations to ActiveRecord models.
11
11
 
12
+ In other words, a way to translate actual user-generated content, for example; a single blog post with multiple translations.
13
+
12
14
  ## Requirements
13
15
 
14
16
  * ActiveRecord >= 4.2.0 (see below for installation with ActiveRecord 3.x)
@@ -28,6 +30,21 @@ When using bundler put this in your Gemfile:
28
30
  gem 'globalize', '~> 5.0.0'
29
31
  ```
30
32
 
33
+ You have to use the **master** branch to work with Rails 5, or you can use a pre-release gem:
34
+
35
+ ```ruby
36
+ gem 'globalize', '~> 5.1.0.beta2'
37
+ ```
38
+
39
+ Please help us by letting us know what works, and what doesn't, when using pre-release code.
40
+
41
+ Put in your Gemfile
42
+
43
+ ```ruby
44
+ gem 'globalize', git: 'https://github.com/globalize/globalize'
45
+ gem 'activemodel-serializers-xml'
46
+ ```
47
+
31
48
  To use the version of globalize for ActiveRecord 4.0 or 4.1, specify:
32
49
 
33
50
  ```ruby
@@ -80,19 +97,24 @@ and `drop_translation_table!` inside the `change` instance method.
80
97
 
81
98
  ### Creating translation tables
82
99
 
83
- ***Do not use the `change` method, use `up` and `down`!***
100
+ Also note that before you can create a translation table, you have to define the translated attributes via `translates` in your model as shown above.
84
101
 
85
102
  ```ruby
86
103
  class CreatePosts < ActiveRecord::Migration
87
- def up
104
+ def change
88
105
  create_table :posts do |t|
89
106
  t.timestamps
90
107
  end
91
- Post.create_translation_table! :title => :string, :text => :text
92
- end
93
- def down
94
- drop_table :posts
95
- Post.drop_translation_table!
108
+
109
+ reversible do |dir|
110
+ dir.up do
111
+ Post.create_translation_table! :title => :string, :text => :text
112
+ end
113
+
114
+ dir.down do
115
+ Post.drop_translation_table!
116
+ end
117
+ end
96
118
  end
97
119
  end
98
120
  ```
@@ -101,16 +123,21 @@ Also, you can pass options for specific columns. Here’s an example:
101
123
 
102
124
  ```ruby
103
125
  class CreatePosts < ActiveRecord::Migration
104
- def up
126
+ def change
105
127
  create_table :posts do |t|
106
128
  t.timestamps
107
129
  end
108
- Post.create_translation_table! :title => :string,
109
- :text => {:type => :text, :null => false, :default => 'abc'}
110
- end
111
- def down
112
- drop_table :posts
113
- Post.drop_translation_table!
130
+
131
+ reversible do |dir|
132
+ dir.up do
133
+ Post.create_translation_table! :title => :string,
134
+ :text => {:type => :text, :null => false, :default => 'abc'}
135
+ end
136
+
137
+ dir.down do
138
+ Post.drop_translation_table!
139
+ end
140
+ end
114
141
  end
115
142
  end
116
143
  ```
@@ -130,6 +157,31 @@ model's attributes as they were before the translation was applied. Here's an
130
157
  example (which assumes you already have a model called `Post` and its table
131
158
  exists):
132
159
 
160
+ ```ruby
161
+ class TranslatePosts < ActiveRecord::Migration
162
+ def change
163
+ reversible do |dir|
164
+ dir.up do
165
+ Post.create_translation_table!({
166
+ :title => :string,
167
+ :text => :text
168
+ }, {
169
+ :migrate_data => true
170
+ })
171
+ end
172
+
173
+ dir.down do
174
+ Post.drop_translation_table! :migrate_data => true
175
+ end
176
+ end
177
+ end
178
+ end
179
+ ```
180
+
181
+ NOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.
182
+
183
+ To automatically remove the translated columns from the parent table after the data migration, please use option `remove_source_columns`.
184
+
133
185
  ```ruby
134
186
  class TranslatePosts < ActiveRecord::Migration
135
187
  def self.up
@@ -137,7 +189,8 @@ class TranslatePosts < ActiveRecord::Migration
137
189
  :title => :string,
138
190
  :text => :text
139
191
  }, {
140
- :migrate_data => true
192
+ :migrate_data => true,
193
+ :remove_source_columns => true
141
194
  })
142
195
  end
143
196
 
@@ -147,7 +200,19 @@ class TranslatePosts < ActiveRecord::Migration
147
200
  end
148
201
  ```
149
202
 
150
- NOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.
203
+
204
+ In order to use a specific locale for migrated data, you can use `I18n.with_locale`:
205
+
206
+ ```ruby
207
+ I18n.with_locale(:bo) do
208
+ Post.create_translation_table!({
209
+ :title => :string,
210
+ :text => :text
211
+ }, {
212
+ :migrate_data => true
213
+ })
214
+ end
215
+ ```
151
216
 
152
217
  ## Adding additional fields to the translation table
153
218
 
@@ -155,12 +220,16 @@ In order to add a new field to an existing translation table, you can use `add_t
155
220
 
156
221
  ```ruby
157
222
  class AddAuthorToPost < ActiveRecord::Migration
158
- def up
159
- Post.add_translation_fields! author: :text
160
- end
161
-
162
- def down
163
- remove_column :post_translations, :author
223
+ def change
224
+ reversible do |dir|
225
+ dir.up do
226
+ Post.add_translation_fields! author: :text
227
+ end
228
+
229
+ dir.down do
230
+ remove_column :post_translations, :author
231
+ end
232
+ end
164
233
  end
165
234
  end
166
235
  ```
@@ -176,6 +245,24 @@ Because globalize uses the `:locale` key to specify the locale during
176
245
  mass-assignment, you should avoid having a `locale` attribute on the parent
177
246
  model.
178
247
 
248
+ If you like your translated model to update if a translation changes, use the `touch: true` option together with `translates`:
249
+
250
+ ```ruby
251
+ translates :name, touch: true
252
+ ```
253
+
254
+ ## Known Issues
255
+
256
+ If you're getting the `ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "column_name" violates not-null constraint` error, the only known way to deal with it as of now is to remove not-null constraint for the globalized columns:
257
+
258
+ ```ruby
259
+ class RemoveNullConstraintsFromResourceTranslations < ActiveRecord::Migration
260
+ def change
261
+ change_column_null :resource_translations, :column_name, true
262
+ end
263
+ end
264
+ ```
265
+
179
266
  ## Versioning with Globalize
180
267
 
181
268
  See the [globalize-versioning](https://github.com/globalize/globalize-versioning) gem.
@@ -327,23 +414,29 @@ def cache_key
327
414
  end
328
415
  ```
329
416
 
417
+ ## Thread-safety
418
+
419
+ Globalize uses [request_store](https://github.com/steveklabnik/request_store) gem to clean up thread-global variable after every request.
420
+ RequestStore includes a Railtie that will configure everything properly for Rails 3+ apps.
421
+
422
+ If you're not using Rails, you may need to consult a RequestStore's [README](https://github.com/steveklabnik/request_store#no-rails-no-problem) to configure it.
423
+
424
+ ## Tutorials and articles
425
+ * [Go Global with Rails and I18n](http://www.sitepoint.com/go-global-rails-i18n/) - introductory article about i18n in Rails (Ilya Bodrov)
426
+
330
427
  ## Official Globalize extensions
331
428
 
332
- * [globalize-accessors](https://github.com/globalize/globalize-accessors) - Replacement for [easy_globalize_3_accessors](https://github.com/paneq/easy_globalize3_accessors) compatible with Globalize 3.x and 4.x.
333
- * [globalize-versioning](https://github.com/globalize/globalize-versioning) - Versioning support for using Globalize with [`paper_trail`](https://github.com/airblade/paper_trail).
429
+ * [globalize-accessors](https://github.com/globalize/globalize-accessors) - generator of accessor methods for models. *(e.g. title_en, title_cz)*
430
+ * [globalize-versioning](https://github.com/globalize/globalize-versioning) - versioning support for using Globalize with [`paper_trail`](https://github.com/airblade/paper_trail). (compatible with Globalize 3.x and 4.x)
334
431
 
335
- ## Alternative Solutions
432
+ ## Alternative solutions
336
433
 
337
- * [Veger's fork](http://github.com/veger/globalize2) - uses default AR schema for the default locale, delegates to the translations table for other locales only
338
- * [TranslatableColumns](http://github.com/iain/translatable_columns) - have multiple languages of the same attribute in a model (Iain Hecker)
339
- * [Traco](https://github.com/barsoom/traco) - A newer take on using multiple columns in the same model (Barsoom)
340
- * [localized_record](http://github.com/glennpow/localized_record) - allows records to have localized attributes without any modifications to the database (Glenn Powell)
341
- * [model_translations](http://github.com/janne/model_translations) - Minimal implementation of Globalize2 style model translations (Jan Andersson)
342
- * [hstore_translate](http://github.com/robworley/hstore_translate) - Rails I18n library for ActiveRecord model/data translation using PostgreSQL's hstore datatype (Rob Worley)
434
+ * [Traco](https://github.com/barsoom/traco) - use multiple columns in the same model (Barsoom)
435
+ * [Mobility](https://github.com/shioyama/mobility) - pluggable translation framework supporting many strategies, including translatable columns, translation tables and hstore/jsonb (Chris Salzberg)
436
+ * [hstore_translate](https://github.com/cfabianski/hstore_translate) - use PostgreSQL's hstore datatype to store translations, instead of separate translation tables (Cédric Fabianski)
437
+ * [json_translate](https://github.com/cfabianski/json_translate) - use PostgreSQL's json/jsonb datatype to store translations, instead of separate translation tables (Cédric Fabianski)
438
+ * [Trasto](https://github.com/yabawock/trasto) - store translations directly in the model in a Postgres Hstore column
343
439
 
344
440
  ## Related solutions
345
441
 
346
- * [globalize2_versioning](http://github.com/joshmh/globalize2_versioning) - acts_as_versioned style versioning for globalize2 (Joshua Harvey)
347
- * [i18n_multi_locales_validations](http://github.com/ZenCocoon/i18n_multi_locales_validations) - multi-locales attributes validations to validates attributes from globalize2 translations models (Sébastien Grosjean)
348
- * [migrate_from_globalize1](http://gist.github.com/120867) - migrate model translations from Globalize1 to globalize2 (Tomasz Stachewicz)
349
- * [batch_translations](http://github.com/rilla/batch_translations) - allow saving multiple globalize2 translations in the same request (Jose Alvarez Rilla)
442
+ * [friendly_id-globalize](https://github.com/norman/friendly_id-globalize) - lets you use Globalize to translate slugs (Norman Clarke)
data/Rakefile CHANGED
@@ -20,3 +20,36 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('README')
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
23
+
24
+ task :load_path do
25
+ %w(lib test).each do |path|
26
+ $LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
27
+ end
28
+ end
29
+
30
+ namespace :db do
31
+ desc 'Create the database'
32
+ task :create => :load_path do
33
+ require 'support/database'
34
+
35
+ Globalize::Test::Database.create!
36
+ end
37
+
38
+ desc "Drop the database"
39
+ task :drop => :load_path do
40
+ require 'support/database'
41
+
42
+ Globalize::Test::Database.drop!
43
+ end
44
+
45
+ desc "Set up the database schema"
46
+ task :migrate => :load_path do
47
+ require 'support/database'
48
+
49
+ Globalize::Test::Database.migrate!
50
+ # ActiveRecord::Schema.migrate :up
51
+ end
52
+
53
+ desc "Drop and recreate the database schema"
54
+ task :reset => [:drop, :create]
55
+ end
@@ -5,6 +5,7 @@ module Globalize
5
5
  options = attr_names.extract_options!
6
6
  # Bypass setup_translates! if the initial bootstrapping is done already.
7
7
  setup_translates!(options) unless translates?
8
+ check_columns!(attr_names)
8
9
 
9
10
  # Add any extra translatable attributes.
10
11
  attr_names = attr_names.map(&:to_sym)
@@ -38,6 +39,30 @@ module Globalize
38
39
  # Add attribute to the list.
39
40
  self.translated_attribute_names << attr_name
40
41
  end
42
+
43
+ begin
44
+ if ::ActiveRecord::VERSION::STRING > "5.0" && table_exists? &&translation_class.table_exists?
45
+ self.ignored_columns += translated_attribute_names.map(&:to_s)
46
+ reset_column_information
47
+ end
48
+ rescue ::ActiveRecord::NoDatabaseError
49
+ warn 'Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.'
50
+ end
51
+ end
52
+
53
+ def check_columns!(attr_names)
54
+ # If tables do not exist or Rails version is greater than 5, do not warn about conflicting columns
55
+ return unless ::ActiveRecord::VERSION::STRING < "5.0" && table_exists? && translation_class.table_exists?
56
+ if (overlap = attr_names.map(&:to_s) & column_names).present?
57
+ ActiveSupport::Deprecation.warn(
58
+ ["You have defined one or more translated attributes with names that conflict with column(s) on the model table. ",
59
+ "Globalize does not support this configuration anymore, remove or rename column(s) on the model table.\n",
60
+ "Model name (table name): #{model_name} (#{table_name})\n",
61
+ "Attribute name(s): #{overlap.join(', ')}\n"].join
62
+ )
63
+ end
64
+ rescue ::ActiveRecord::NoDatabaseError
65
+ warn 'Unable to connect to a database. Globalize skipped checking attributes with conflicting column names.'
41
66
  end
42
67
 
43
68
  def apply_globalize_options(options)
@@ -74,10 +99,11 @@ module Globalize
74
99
  :foreign_key => options[:foreign_key],
75
100
  :dependent => :destroy,
76
101
  :extend => HasManyExtensions,
77
- :autosave => false
102
+ :autosave => true,
103
+ :inverse_of => :globalized_model
78
104
 
79
- after_create :save_translations!
80
- after_update :save_translations!
105
+ before_create :save_translations!
106
+ before_update :save_translations!
81
107
  end
82
108
  end
83
109