globalize 5.0.1 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +19 -5
- data/Gemfile.lock +97 -47
- data/{readme.md → README.md} +116 -35
- data/Rakefile +33 -0
- data/lib/globalize.rb +11 -5
- data/lib/globalize/active_record.rb +1 -0
- data/lib/globalize/active_record/act_macro.rb +24 -3
- data/lib/globalize/active_record/adapter.rb +10 -11
- data/lib/globalize/active_record/adapter_dirty.rb +54 -0
- data/lib/globalize/active_record/class_methods.rb +15 -6
- data/lib/globalize/active_record/exceptions.rb +1 -7
- data/lib/globalize/active_record/instance_methods.rb +55 -35
- data/lib/globalize/active_record/migration.rb +51 -29
- data/lib/globalize/active_record/query_methods.rb +42 -17
- data/lib/globalize/version.rb +1 -1
- data/lib/patches/active_record/persistence.rb +6 -15
- data/lib/patches/active_record/query_method.rb +2 -34
- data/lib/patches/active_record/rails4/query_method.rb +35 -0
- data/lib/patches/active_record/rails4/uniqueness_validator.rb +42 -0
- data/lib/patches/active_record/rails5/uniqueness_validator.rb +47 -0
- data/lib/patches/active_record/relation.rb +12 -0
- data/lib/patches/active_record/serialization.rb +13 -16
- data/lib/patches/active_record/uniqueness_validator.rb +5 -39
- data/lib/patches/active_record/xml_attribute_serializer.rb +19 -9
- metadata +27 -24
- data/globalize.gemspec +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08ebfb553ad5faf8e55d1b120bbafd8571327e2
|
4
|
+
data.tar.gz: b30cca9abefcb65933dcbff2ace3040f40cbfea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ead976f8983d5477cce5d9e518f48997c7fdedb3abd057a79946fda0828943672069e286c3c9deff5d5ef53f8faebf24a3081f4e4bb323f9e9e5375fe95af5a8
|
7
|
+
data.tar.gz: 7dd8d873d8492109cffa6561d6a57829f8b7d737f8125dd200a853ac11bcb6f8774c615b5cdd3c024223d81a6841c1c0d9d79481f6a77c11328d4ad363e9c4de
|
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
|
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
|
10
|
+
gem "rubysl", "~> 2.0"
|
11
|
+
gem "rubinius-developer_tools"
|
7
12
|
end
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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,88 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/jruby/activerecord-jdbc-adapter
|
3
|
+
revision: 8c734333384b0e2c49eb3c331fdebc28726d8248
|
4
|
+
specs:
|
5
|
+
activerecord-jdbc-adapter (1.4.0.dev-java)
|
6
|
+
jar-dependencies (~> 0.1.13)
|
7
|
+
activerecord-jdbcmysql-adapter (1.4.0.dev)
|
8
|
+
activerecord-jdbc-adapter (~> 1.4.0.dev)
|
9
|
+
jdbc-mysql (>= 5.1.22)
|
10
|
+
activerecord-jdbcpostgresql-adapter (1.4.0.dev)
|
11
|
+
activerecord-jdbc-adapter (~> 1.4.0.dev)
|
12
|
+
jdbc-postgres (>= 9.1)
|
13
|
+
activerecord-jdbcsqlite3-adapter (1.4.0.dev)
|
14
|
+
activerecord-jdbc-adapter (~> 1.4.0.dev)
|
15
|
+
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
16
|
+
jdbc-mysql (5.1.39)
|
17
|
+
jdbc-postgres (9.4.1206)
|
18
|
+
jdbc-sqlite3 (3.8.11.2)
|
19
|
+
|
1
20
|
PATH
|
2
21
|
remote: .
|
3
22
|
specs:
|
4
|
-
globalize (5.0
|
5
|
-
activemodel (>= 4.2
|
6
|
-
activerecord (>= 4.2
|
23
|
+
globalize (5.1.0)
|
24
|
+
activemodel (>= 4.2, < 5.1)
|
25
|
+
activerecord (>= 4.2, < 5.1)
|
26
|
+
request_store (~> 1.0)
|
7
27
|
|
8
28
|
GEM
|
9
29
|
remote: https://rubygems.org/
|
10
30
|
specs:
|
11
|
-
activemodel (
|
12
|
-
activesupport (=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
31
|
+
activemodel (5.0.0)
|
32
|
+
activesupport (= 5.0.0)
|
33
|
+
activerecord (5.0.0)
|
34
|
+
activemodel (= 5.0.0)
|
35
|
+
activesupport (= 5.0.0)
|
36
|
+
arel (~> 7.0)
|
37
|
+
activesupport (5.0.0)
|
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.
|
25
|
-
arel (
|
42
|
+
ansi (1.5.0)
|
43
|
+
arel (7.0.0)
|
26
44
|
builder (3.2.2)
|
27
|
-
coderay (1.1.
|
28
|
-
|
45
|
+
coderay (1.1.1)
|
46
|
+
concurrent-ruby (1.0.2)
|
47
|
+
concurrent-ruby (1.0.2-java)
|
48
|
+
database_cleaner (1.5.3)
|
49
|
+
ffi (1.9.14-java)
|
29
50
|
ffi2-generators (0.1.1)
|
30
51
|
i18n (0.7.0)
|
31
|
-
|
52
|
+
jar-dependencies (0.1.15)
|
53
|
+
json (1.8.3)
|
54
|
+
json (1.8.3-java)
|
32
55
|
method_source (0.8.2)
|
33
|
-
minitest (5.
|
34
|
-
minitest-reporters (1.
|
56
|
+
minitest (5.9.0)
|
57
|
+
minitest-reporters (1.1.10)
|
35
58
|
ansi
|
36
59
|
builder
|
37
60
|
minitest (>= 5.0)
|
38
61
|
ruby-progressbar
|
39
|
-
|
62
|
+
mysql2 (0.4.4)
|
63
|
+
pg (0.18.4)
|
64
|
+
pry (0.10.4)
|
40
65
|
coderay (~> 1.1.0)
|
41
66
|
method_source (~> 0.8.1)
|
42
67
|
slop (~> 3.4)
|
43
|
-
pry
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
68
|
+
pry (0.10.4-java)
|
69
|
+
coderay (~> 1.1.0)
|
70
|
+
method_source (~> 0.8.1)
|
71
|
+
slop (~> 3.4)
|
72
|
+
spoon (~> 0.0)
|
73
|
+
rake (11.2.2)
|
74
|
+
rdoc (4.2.2)
|
75
|
+
json (~> 1.4)
|
76
|
+
request_store (1.3.1)
|
77
|
+
rubinius-coverage (2.1)
|
78
|
+
rubinius-debugger (2.4)
|
79
|
+
rubinius-developer_tools (2.0.0)
|
80
|
+
rubinius-coverage (~> 2.0)
|
81
|
+
rubinius-debugger (~> 2.0)
|
82
|
+
rubinius-profiler (~> 2.0)
|
83
|
+
rubinius-profiler (2.1)
|
84
|
+
ruby-progressbar (1.8.1)
|
85
|
+
rubysl (2.2.0)
|
50
86
|
rubysl-abbrev (~> 2.0)
|
51
87
|
rubysl-base64 (~> 2.0)
|
52
88
|
rubysl-benchmark (~> 2.0)
|
@@ -131,6 +167,7 @@ GEM
|
|
131
167
|
rubysl-tmpdir (~> 2.0)
|
132
168
|
rubysl-tsort (~> 2.0)
|
133
169
|
rubysl-un (~> 2.0)
|
170
|
+
rubysl-unicode_normalize (~> 2.0)
|
134
171
|
rubysl-uri (~> 2.0)
|
135
172
|
rubysl-weakref (~> 2.0)
|
136
173
|
rubysl-webrick (~> 2.0)
|
@@ -142,17 +179,17 @@ GEM
|
|
142
179
|
rubysl-benchmark (2.0.1)
|
143
180
|
rubysl-bigdecimal (2.0.2)
|
144
181
|
rubysl-cgi (2.0.1)
|
145
|
-
rubysl-cgi-session (2.0
|
182
|
+
rubysl-cgi-session (2.1.0)
|
146
183
|
rubysl-cmath (2.0.0)
|
147
184
|
rubysl-complex (2.0.0)
|
148
185
|
rubysl-continuation (2.0.0)
|
149
|
-
rubysl-coverage (2.
|
186
|
+
rubysl-coverage (2.1)
|
150
187
|
rubysl-csv (2.0.2)
|
151
188
|
rubysl-english (~> 2.0)
|
152
189
|
rubysl-curses (2.0.1)
|
153
|
-
rubysl-date (2.0.
|
190
|
+
rubysl-date (2.0.9)
|
154
191
|
rubysl-delegate (2.0.1)
|
155
|
-
rubysl-digest (2.0.
|
192
|
+
rubysl-digest (2.0.8)
|
156
193
|
rubysl-drb (2.0.1)
|
157
194
|
rubysl-e2mmap (2.0.0)
|
158
195
|
rubysl-english (2.0.0)
|
@@ -175,8 +212,7 @@ GEM
|
|
175
212
|
rubysl-io-nonblock (2.0.0)
|
176
213
|
rubysl-io-wait (2.0.0)
|
177
214
|
rubysl-ipaddr (2.0.0)
|
178
|
-
rubysl-irb (2.1.
|
179
|
-
rb-readline (~> 0.5)
|
215
|
+
rubysl-irb (2.1.1)
|
180
216
|
rubysl-e2mmap (~> 2.0)
|
181
217
|
rubysl-mathn (~> 2.0)
|
182
218
|
rubysl-thread (~> 2.0)
|
@@ -184,7 +220,7 @@ GEM
|
|
184
220
|
rubysl-mathn (2.0.0)
|
185
221
|
rubysl-matrix (2.1.0)
|
186
222
|
rubysl-e2mmap (~> 2.0)
|
187
|
-
rubysl-mkmf (2.
|
223
|
+
rubysl-mkmf (2.1)
|
188
224
|
rubysl-fileutils (~> 2.0)
|
189
225
|
rubysl-shellwords (~> 2.0)
|
190
226
|
rubysl-monitor (2.0.0)
|
@@ -203,19 +239,19 @@ GEM
|
|
203
239
|
rubysl-observer (2.0.0)
|
204
240
|
rubysl-open-uri (2.0.0)
|
205
241
|
rubysl-open3 (2.0.0)
|
206
|
-
rubysl-openssl (2.
|
242
|
+
rubysl-openssl (2.8.0)
|
207
243
|
rubysl-optparse (2.0.1)
|
208
244
|
rubysl-shellwords (~> 2.0)
|
209
|
-
rubysl-ostruct (2.0
|
210
|
-
rubysl-pathname (2.
|
245
|
+
rubysl-ostruct (2.1.0)
|
246
|
+
rubysl-pathname (2.3)
|
211
247
|
rubysl-prettyprint (2.0.3)
|
212
248
|
rubysl-prime (2.0.1)
|
213
249
|
rubysl-profile (2.0.0)
|
214
|
-
rubysl-profiler (2.
|
250
|
+
rubysl-profiler (2.1)
|
215
251
|
rubysl-pstore (2.0.0)
|
216
252
|
rubysl-pty (2.0.3)
|
217
253
|
rubysl-rational (2.0.1)
|
218
|
-
rubysl-resolv (2.1.
|
254
|
+
rubysl-resolv (2.1.2)
|
219
255
|
rubysl-rexml (2.0.4)
|
220
256
|
rubysl-rinda (2.0.1)
|
221
257
|
rubysl-rss (2.0.0)
|
@@ -224,14 +260,15 @@ GEM
|
|
224
260
|
rubysl-set (2.0.1)
|
225
261
|
rubysl-shellwords (2.0.0)
|
226
262
|
rubysl-singleton (2.0.0)
|
227
|
-
rubysl-socket (2.
|
228
|
-
|
263
|
+
rubysl-socket (2.1.2)
|
264
|
+
rubysl-fcntl (~> 2.0)
|
265
|
+
rubysl-stringio (2.1.0)
|
229
266
|
rubysl-strscan (2.0.0)
|
230
267
|
rubysl-sync (2.0.0)
|
231
268
|
rubysl-syslog (2.1.0)
|
232
269
|
ffi2-generators (~> 0.1)
|
233
270
|
rubysl-tempfile (2.0.1)
|
234
|
-
rubysl-thread (2.0.
|
271
|
+
rubysl-thread (2.0.3)
|
235
272
|
rubysl-thwait (2.0.0)
|
236
273
|
rubysl-time (2.0.3)
|
237
274
|
rubysl-timeout (2.0.0)
|
@@ -240,6 +277,7 @@ GEM
|
|
240
277
|
rubysl-un (2.0.0)
|
241
278
|
rubysl-fileutils (~> 2.0)
|
242
279
|
rubysl-optparse (~> 2.0)
|
280
|
+
rubysl-unicode_normalize (2.0)
|
243
281
|
rubysl-uri (2.0.0)
|
244
282
|
rubysl-weakref (2.0.0)
|
245
283
|
rubysl-webrick (2.0.0)
|
@@ -247,22 +285,34 @@ GEM
|
|
247
285
|
rubysl-yaml (2.1.0)
|
248
286
|
rubysl-zlib (2.0.1)
|
249
287
|
slop (3.6.0)
|
250
|
-
|
251
|
-
|
288
|
+
spoon (0.0.4)
|
289
|
+
ffi
|
290
|
+
sqlite3 (1.3.11)
|
291
|
+
thread_safe (0.3.5)
|
292
|
+
thread_safe (0.3.5-java)
|
252
293
|
tzinfo (1.2.2)
|
253
294
|
thread_safe (~> 0.1)
|
254
295
|
|
255
296
|
PLATFORMS
|
297
|
+
java
|
256
298
|
ruby
|
257
299
|
|
258
300
|
DEPENDENCIES
|
259
|
-
|
301
|
+
activerecord-jdbcmysql-adapter!
|
302
|
+
activerecord-jdbcpostgresql-adapter!
|
303
|
+
activerecord-jdbcsqlite3-adapter!
|
304
|
+
database_cleaner
|
260
305
|
globalize!
|
261
306
|
minitest
|
262
307
|
minitest-reporters
|
308
|
+
mysql2
|
309
|
+
pg
|
263
310
|
pry
|
264
|
-
pry-nav
|
265
311
|
rake
|
266
312
|
rdoc
|
313
|
+
rubinius-developer_tools
|
267
314
|
rubysl (~> 2.0)
|
268
315
|
sqlite3
|
316
|
+
|
317
|
+
BUNDLED WITH
|
318
|
+
1.13.4
|
data/{readme.md → README.md}
RENAMED
@@ -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,15 @@ When using bundler put this in your Gemfile:
|
|
28
30
|
gem 'globalize', '~> 5.0.0'
|
29
31
|
```
|
30
32
|
|
33
|
+
You have to use branch **master** to work with Rails 5.
|
34
|
+
|
35
|
+
Put in your Gemfile
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'globalize', git: 'https://github.com/globalize/globalize'
|
39
|
+
gem 'activemodel-serializers-xml'
|
40
|
+
```
|
41
|
+
|
31
42
|
To use the version of globalize for ActiveRecord 4.0 or 4.1, specify:
|
32
43
|
|
33
44
|
```ruby
|
@@ -80,19 +91,24 @@ and `drop_translation_table!` inside the `change` instance method.
|
|
80
91
|
|
81
92
|
### Creating translation tables
|
82
93
|
|
83
|
-
|
94
|
+
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
95
|
|
85
96
|
```ruby
|
86
97
|
class CreatePosts < ActiveRecord::Migration
|
87
|
-
def
|
98
|
+
def change
|
88
99
|
create_table :posts do |t|
|
89
100
|
t.timestamps
|
90
101
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
102
|
+
|
103
|
+
reversible do |dir|
|
104
|
+
dir.up do
|
105
|
+
Post.create_translation_table! :title => :string, :text => :text
|
106
|
+
end
|
107
|
+
|
108
|
+
dir.down do
|
109
|
+
Post.drop_translation_table!
|
110
|
+
end
|
111
|
+
end
|
96
112
|
end
|
97
113
|
end
|
98
114
|
```
|
@@ -101,16 +117,21 @@ Also, you can pass options for specific columns. Here’s an example:
|
|
101
117
|
|
102
118
|
```ruby
|
103
119
|
class CreatePosts < ActiveRecord::Migration
|
104
|
-
def
|
120
|
+
def change
|
105
121
|
create_table :posts do |t|
|
106
122
|
t.timestamps
|
107
123
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
124
|
+
|
125
|
+
reversible do |dir|
|
126
|
+
dir.up do
|
127
|
+
Post.create_translation_table! :title => :string,
|
128
|
+
:text => {:type => :text, :null => false, :default => 'abc'}
|
129
|
+
end
|
130
|
+
|
131
|
+
dir.down do
|
132
|
+
Post.drop_translation_table!
|
133
|
+
end
|
134
|
+
end
|
114
135
|
end
|
115
136
|
end
|
116
137
|
```
|
@@ -130,6 +151,31 @@ model's attributes as they were before the translation was applied. Here's an
|
|
130
151
|
example (which assumes you already have a model called `Post` and its table
|
131
152
|
exists):
|
132
153
|
|
154
|
+
```ruby
|
155
|
+
class TranslatePosts < ActiveRecord::Migration
|
156
|
+
def change
|
157
|
+
reversible do |dir|
|
158
|
+
dir.up do
|
159
|
+
Post.create_translation_table!({
|
160
|
+
:title => :string,
|
161
|
+
:text => :text
|
162
|
+
}, {
|
163
|
+
:migrate_data => true
|
164
|
+
})
|
165
|
+
end
|
166
|
+
|
167
|
+
dir.down do
|
168
|
+
Post.drop_translation_table! :migrate_data => true
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
175
|
+
NOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.
|
176
|
+
|
177
|
+
To automatically remove the translated columns from the parent table after the data migration, please use option `remove_source_columns`.
|
178
|
+
|
133
179
|
```ruby
|
134
180
|
class TranslatePosts < ActiveRecord::Migration
|
135
181
|
def self.up
|
@@ -137,7 +183,8 @@ class TranslatePosts < ActiveRecord::Migration
|
|
137
183
|
:title => :string,
|
138
184
|
:text => :text
|
139
185
|
}, {
|
140
|
-
:migrate_data => true
|
186
|
+
:migrate_data => true,
|
187
|
+
:remove_source_columns => true
|
141
188
|
})
|
142
189
|
end
|
143
190
|
|
@@ -147,7 +194,19 @@ class TranslatePosts < ActiveRecord::Migration
|
|
147
194
|
end
|
148
195
|
```
|
149
196
|
|
150
|
-
|
197
|
+
|
198
|
+
In order to use a specific locale for migrated data, you can use `I18n.with_locale`:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
I18n.with_locale(:bo) do
|
202
|
+
Post.create_translation_table!({
|
203
|
+
:title => :string,
|
204
|
+
:text => :text
|
205
|
+
}, {
|
206
|
+
:migrate_data => true
|
207
|
+
})
|
208
|
+
end
|
209
|
+
```
|
151
210
|
|
152
211
|
## Adding additional fields to the translation table
|
153
212
|
|
@@ -155,12 +214,16 @@ In order to add a new field to an existing translation table, you can use `add_t
|
|
155
214
|
|
156
215
|
```ruby
|
157
216
|
class AddAuthorToPost < ActiveRecord::Migration
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
217
|
+
def change
|
218
|
+
reversible do |dir|
|
219
|
+
dir.up do
|
220
|
+
Post.add_translation_fields! author: :text
|
221
|
+
end
|
222
|
+
|
223
|
+
dir.down do
|
224
|
+
remove_column :post_translations, :author
|
225
|
+
end
|
226
|
+
end
|
164
227
|
end
|
165
228
|
end
|
166
229
|
```
|
@@ -176,6 +239,18 @@ Because globalize uses the `:locale` key to specify the locale during
|
|
176
239
|
mass-assignment, you should avoid having a `locale` attribute on the parent
|
177
240
|
model.
|
178
241
|
|
242
|
+
## Known Issues
|
243
|
+
|
244
|
+
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:
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
class RemoveNullConstraintsFromResources < ActiveRecord::Migration
|
248
|
+
def change
|
249
|
+
change_column_null :resources, :column_name, true
|
250
|
+
end
|
251
|
+
end
|
252
|
+
```
|
253
|
+
|
179
254
|
## Versioning with Globalize
|
180
255
|
|
181
256
|
See the [globalize-versioning](https://github.com/globalize/globalize-versioning) gem.
|
@@ -327,23 +402,29 @@ def cache_key
|
|
327
402
|
end
|
328
403
|
```
|
329
404
|
|
405
|
+
## Thread-safety
|
406
|
+
|
407
|
+
Globalize uses [request_store](https://github.com/steveklabnik/request_store) gem to clean up thread-global variable after every request.
|
408
|
+
RequestStore includes a Railtie that will configure everything properly for Rails 3+ apps.
|
409
|
+
|
410
|
+
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.
|
411
|
+
|
412
|
+
## Tutorials and articles
|
413
|
+
* [Go Global with Rails and I18n](http://www.sitepoint.com/go-global-rails-i18n/) - introductory article about i18n in Rails (Ilya Bodrov)
|
414
|
+
|
330
415
|
## Official Globalize extensions
|
331
416
|
|
332
|
-
* [globalize-accessors](https://github.com/globalize/globalize-accessors) -
|
333
|
-
* [globalize-versioning](https://github.com/globalize/globalize-versioning) -
|
417
|
+
* [globalize-accessors](https://github.com/globalize/globalize-accessors) - generator of accessor methods for models. *(e.g. title_en, title_cz)*
|
418
|
+
* [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
419
|
|
335
|
-
## Alternative
|
420
|
+
## Alternative solutions
|
336
421
|
|
337
|
-
* [
|
338
|
-
* [
|
339
|
-
* [
|
340
|
-
* [
|
341
|
-
* [
|
342
|
-
* [hstore_translate](http://github.com/robworley/hstore_translate) - Rails I18n library for ActiveRecord model/data translation using PostgreSQL's hstore datatype (Rob Worley)
|
422
|
+
* [Traco](https://github.com/barsoom/traco) - use multiple columns in the same model (Barsoom)
|
423
|
+
* [Mobility](https://github.com/shioyama/mobility) - pluggable translation framework supporting many strategies, including translatable columns, translation tables and hstore/jsonb (Chris Salzberg)
|
424
|
+
* [hstore_translate](https://github.com/cfabianski/hstore_translate) - use PostgreSQL's hstore datatype to store translations, instead of separate translation tables (Cédric Fabianski)
|
425
|
+
* [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)
|
426
|
+
* [Trasto](https://github.com/yabawock/trasto) - store translations directly in the model in a Postgres Hstore column
|
343
427
|
|
344
428
|
## Related solutions
|
345
429
|
|
346
|
-
* [
|
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)
|
430
|
+
* [friendly_id-globalize](https://github.com/norman/friendly_id-globalize) - lets you use Globalize to translate slugs (Norman Clarke)
|