globalize 6.3.0 → 7.0.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.
- checksums.yaml +4 -4
- data/Appraisals +2 -13
- data/CHANGELOG.md +8 -1
- data/CONTRIBUTING.md +2 -4
- data/Gemfile +8 -0
- data/Gemfile.lock +45 -43
- data/README.md +37 -47
- data/Rakefile +22 -17
- data/lib/globalize/active_record/act_macro.rb +20 -22
- data/lib/globalize/active_record/adapter_dirty.rb +2 -11
- data/lib/globalize/active_record/class_methods.rb +7 -8
- data/lib/globalize/active_record/instance_methods.rb +21 -56
- data/lib/globalize/active_record/migration.rb +7 -21
- data/lib/globalize/active_record/translated_attributes_query.rb +0 -17
- data/lib/globalize/version.rb +1 -1
- data/lib/globalize.rb +14 -34
- data/lib/patches/active_record/rails7_1/serialization.rb +28 -0
- data/lib/patches/active_record/rails7_2/serialization.rb +15 -0
- data/lib/patches/active_record/relation.rb +11 -15
- data/lib/patches/active_record/serialization.rb +5 -5
- data/lib/patches/active_record/uniqueness_validator.rb +1 -9
- data/lib/patches/active_support/inflections.rb +8 -10
- metadata +38 -54
- checksums.yaml.gz.sig +0 -0
- data/docker-compose.yml +0 -22
- data/globalize.gemspec +0 -37
- data/issue_template.rb +0 -38
- data/lib/patches/active_record/query_method.rb +0 -3
- data/lib/patches/active_record/rails4/query_method.rb +0 -35
- data/lib/patches/active_record/rails4/serialization.rb +0 -22
- data/lib/patches/active_record/rails4/uniqueness_validator.rb +0 -42
- data/lib/patches/active_record/rails5/uniqueness_validator.rb +0 -47
- data/lib/patches/active_record/rails5_1/serialization.rb +0 -22
- data/lib/patches/active_record/rails5_1/uniqueness_validator.rb +0 -45
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5fdba3c5ea00eef1837da1b42d82ac9cd09b4ab5ae7ac30c7f52dae27b9f9f1
|
4
|
+
data.tar.gz: 050116cc35980cd4811d50d77b1bd951fd771f166d9bda3fac4e9017915c6392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60221a6bc834b88ae87b49ffbbdb91e580d7e62e8bddb550e256abb7ff3e3d8d2e431655ae2412756700e8faf7e626a873191a47f7b09b2246d74077bc5f0f25
|
7
|
+
data.tar.gz: 130ea35e74944c52893b4923a6168922696bc15f8afaf19e10dfae57913fb19ac2ea10130a6da1d9bbad96ba575a0f71f36848d7a41299ece7b0e6256b37deb1
|
data/Appraisals
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RAILS_VERSIONS = %w[
|
4
|
-
4.2.11.3
|
5
|
-
5.1.7
|
6
|
-
5.2.5
|
7
|
-
6.0.3.6
|
8
|
-
6.1.3.1
|
9
4
|
7.0.1
|
10
5
|
]
|
11
6
|
|
@@ -13,14 +8,8 @@ RAILS_VERSIONS.each do |version|
|
|
13
8
|
appraise "rails_#{version}" do
|
14
9
|
gem 'activemodel', version
|
15
10
|
gem 'activerecord', version
|
16
|
-
|
17
|
-
|
18
|
-
gem 'sqlite3', '~> 1.3.6', platforms: [:ruby, :rbx]
|
19
|
-
elsif version =~ /^5/
|
20
|
-
gem 'sqlite3', '~> 1.3', '>= 1.3.6', platforms: [:ruby, :rbx]
|
21
|
-
else
|
22
|
-
gem 'sqlite3', '~> 1.4', platforms: [:ruby, :rbx]
|
23
|
-
end
|
11
|
+
|
12
|
+
gem 'sqlite3', '~> 1.4', platforms: [:ruby, :rbx]
|
24
13
|
|
25
14
|
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
26
15
|
group :postgres, :postgresql do
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
# Globalize Changelog
|
2
2
|
|
3
|
+
## 7.0.0 (2024-12-20)
|
4
|
+
|
5
|
+
* Enable Rubygems Trusted Publishing
|
6
|
+
* Fix ActiveRecord load order issues using `ActiveSupport.on_load(:active_record)` [#816](https://github.com/globalize/globalize/pull/816) by [Rune Philosof](https://github.com/runephilosof-abtion)
|
7
|
+
* Allow custom `:dependent` option for translations association [#821](https://github.com/globalize/globalize/pull/821) by [Bruno Carvalho](https://github.com/brunodccarvalho)
|
8
|
+
* Don't specify `ignored_columns` unless necessary [#806](https://github.com/globalize/globalize/pull/806) by [Pat Leamon](https://github.com/stiak)
|
9
|
+
|
3
10
|
## 6.3.0 (2023-10-22)
|
4
11
|
|
5
|
-
* Support ruby 3.2 rails 7.1
|
12
|
+
* Support ruby 3.2 rails 7.1 [#810](https://github.com/globalize/globalize/pull/810) by [Shinichi Maeshima](https://github.com/willnet)
|
6
13
|
|
7
14
|
## 6.2.1 (2022-05-24)
|
8
15
|
|
data/CONTRIBUTING.md
CHANGED
@@ -4,7 +4,7 @@ Globalize is a community project, and would not be here today if it were not for
|
|
4
4
|
|
5
5
|
## Bugs
|
6
6
|
|
7
|
-
If you find a bug or something is not working as expected, please search through the [github issues](https://github.com/globalize/globalize/issues) and on [stackoverflow](http://stackoverflow.com/questions/tagged/globalize) first. If you cannot find any answers related to your issue, post a new one and we will try to address it as soon as we can.
|
7
|
+
If you find a bug or something is not working as expected, please search through the [github issues](https://github.com/globalize/globalize/issues) and on [stackoverflow](http://stackoverflow.com/questions/tagged/globalize) first. If you cannot find any answers related to your issue, post a new one and we will try to address it as soon as we can.
|
8
8
|
|
9
9
|
If you also have some idea how to fix the bug, then by all means post a pull request (see below).
|
10
10
|
|
@@ -20,7 +20,7 @@ Have some free time? Help us improve our [code climate score](https://codeclimat
|
|
20
20
|
|
21
21
|
## Documentation
|
22
22
|
|
23
|
-
Globalize needs better documentation. That includes more inline comments explaining clearly what code is doing, as well as reference documentation beyond the [readme](
|
23
|
+
Globalize needs better documentation. That includes more inline comments explaining clearly what code is doing, as well as reference documentation beyond the [readme](README.md) -- possibly in the github wiki. Please contact us if you would like to help with documentation.
|
24
24
|
|
25
25
|
## Pull Requests
|
26
26
|
|
@@ -32,8 +32,6 @@ Have a bug fix, code improvement or proposed feature? Do the following:
|
|
32
32
|
4. Push to the branch: `git push origin my_new_feature`
|
33
33
|
5. Submit a pull request.
|
34
34
|
|
35
|
-
For pull requests to Rails/ActiveRecord 4 version of Globalize (v3.x), post to the `main` branch. For pull requests to the Rails/ActiveRecord 3.x version of Globalize (3.x), post to the `3-0-stable` branch.
|
36
|
-
|
37
35
|
When you submit the pull request, GitHub Actions will run the [test suite](https://github.com/globalize/globalize/actions) against your branch and will highlight any failures. Unless there is a good reason for it, we do not generally accept pull requests that take Globalize from green to red.
|
38
36
|
|
39
37
|
## Testing
|
data/Gemfile
CHANGED
@@ -7,12 +7,20 @@ if !ENV['CI'] || ENV['DB'] == 'sqlite3'
|
|
7
7
|
gem 'sqlite3', platforms: [:ruby, :rbx]
|
8
8
|
end
|
9
9
|
|
10
|
+
# have a look at test/support/database.yml which environment variables can be set
|
10
11
|
if !ENV['CI'] || ENV['DB'] == 'mysql'
|
11
12
|
group :mysql do
|
12
13
|
gem 'mysql2', platforms: [:ruby, :rbx]
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
# Test with different ActiveRecord versions
|
18
|
+
# $ AR=7.1.5 bundle update; rake db:reset db:migrate test
|
19
|
+
# $ AR=7.2.2 bundle update; rake db:reset db:migrate test
|
20
|
+
if ENV['AR']
|
21
|
+
gem 'activerecord', ENV['AR']
|
22
|
+
end
|
23
|
+
|
16
24
|
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
17
25
|
group :postgres, :postgresql do
|
18
26
|
gem 'pg', platforms: [:ruby, :rbx]
|
data/Gemfile.lock
CHANGED
@@ -1,86 +1,91 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
globalize (
|
5
|
-
activemodel (>=
|
6
|
-
activerecord (>=
|
4
|
+
globalize (7.0.0)
|
5
|
+
activemodel (>= 7.0, < 8.1)
|
6
|
+
activerecord (>= 7.0, < 8.1)
|
7
|
+
activesupport (>= 7.0, < 8.1)
|
7
8
|
request_store (~> 1.0)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
activemodel (
|
13
|
-
activesupport (=
|
14
|
-
activerecord (
|
15
|
-
activemodel (=
|
16
|
-
activesupport (=
|
13
|
+
activemodel (8.0.1)
|
14
|
+
activesupport (= 8.0.1)
|
15
|
+
activerecord (8.0.1)
|
16
|
+
activemodel (= 8.0.1)
|
17
|
+
activesupport (= 8.0.1)
|
17
18
|
timeout (>= 0.4.0)
|
18
|
-
activesupport (
|
19
|
+
activesupport (8.0.1)
|
19
20
|
base64
|
21
|
+
benchmark (>= 0.3)
|
20
22
|
bigdecimal
|
21
|
-
concurrent-ruby (~> 1.0, >= 1.
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
22
24
|
connection_pool (>= 2.2.5)
|
23
25
|
drb
|
24
26
|
i18n (>= 1.6, < 2)
|
27
|
+
logger (>= 1.4.2)
|
25
28
|
minitest (>= 5.1)
|
26
|
-
|
27
|
-
tzinfo (~> 2.0)
|
29
|
+
securerandom (>= 0.3)
|
30
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
31
|
+
uri (>= 0.13.1)
|
28
32
|
ansi (1.5.0)
|
29
33
|
appraisal (2.5.0)
|
30
34
|
bundler
|
31
35
|
rake
|
32
36
|
thor (>= 0.14.0)
|
33
|
-
base64 (0.
|
34
|
-
|
35
|
-
|
37
|
+
base64 (0.2.0)
|
38
|
+
benchmark (0.4.0)
|
39
|
+
bigdecimal (3.1.8)
|
40
|
+
builder (3.3.0)
|
36
41
|
coderay (1.1.3)
|
37
|
-
concurrent-ruby (1.
|
42
|
+
concurrent-ruby (1.3.4)
|
38
43
|
connection_pool (2.4.1)
|
39
|
-
database_cleaner (2.0
|
44
|
+
database_cleaner (2.1.0)
|
40
45
|
database_cleaner-active_record (>= 2, < 3)
|
41
|
-
database_cleaner-active_record (2.
|
46
|
+
database_cleaner-active_record (2.2.0)
|
42
47
|
activerecord (>= 5.a)
|
43
48
|
database_cleaner-core (~> 2.0.0)
|
44
49
|
database_cleaner-core (2.0.1)
|
45
|
-
|
46
|
-
|
47
|
-
i18n (1.14.
|
50
|
+
date (3.4.1)
|
51
|
+
drb (2.2.1)
|
52
|
+
i18n (1.14.6)
|
48
53
|
concurrent-ruby (~> 1.0)
|
54
|
+
logger (1.6.4)
|
49
55
|
m (1.6.2)
|
50
56
|
method_source (>= 0.6.7)
|
51
57
|
rake (>= 0.9.2.2)
|
52
|
-
method_source (1.
|
53
|
-
minitest (5.
|
54
|
-
minitest-reporters (1.
|
58
|
+
method_source (1.1.0)
|
59
|
+
minitest (5.25.4)
|
60
|
+
minitest-reporters (1.7.1)
|
55
61
|
ansi
|
56
62
|
builder
|
57
63
|
minitest (>= 5.0)
|
58
64
|
ruby-progressbar
|
59
|
-
|
60
|
-
mysql2 (0.5.5)
|
61
|
-
pg (1.5.4)
|
62
|
-
pry (0.14.2)
|
65
|
+
pry (0.15.0)
|
63
66
|
coderay (~> 1.1)
|
64
67
|
method_source (~> 1.0)
|
65
|
-
psych (5.
|
68
|
+
psych (5.2.2)
|
69
|
+
date
|
66
70
|
stringio
|
67
|
-
rack (3.
|
68
|
-
rake (13.
|
69
|
-
rdoc (6.
|
71
|
+
rack (3.1.8)
|
72
|
+
rake (13.2.1)
|
73
|
+
rdoc (6.10.0)
|
70
74
|
psych (>= 4.0.0)
|
71
|
-
request_store (1.
|
75
|
+
request_store (1.7.0)
|
72
76
|
rack (>= 1.4)
|
73
77
|
ruby-progressbar (1.13.0)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
timeout (0.4.0)
|
78
|
+
securerandom (0.4.1)
|
79
|
+
stringio (3.1.2)
|
80
|
+
thor (1.3.2)
|
81
|
+
timeout (0.4.3)
|
79
82
|
tzinfo (2.0.6)
|
80
83
|
concurrent-ruby (~> 1.0)
|
84
|
+
uri (1.0.2)
|
81
85
|
|
82
86
|
PLATFORMS
|
83
|
-
|
87
|
+
ruby
|
88
|
+
x86_64-linux
|
84
89
|
|
85
90
|
DEPENDENCIES
|
86
91
|
appraisal
|
@@ -89,12 +94,9 @@ DEPENDENCIES
|
|
89
94
|
m
|
90
95
|
minitest
|
91
96
|
minitest-reporters
|
92
|
-
mysql2
|
93
|
-
pg
|
94
97
|
pry
|
95
98
|
rake
|
96
99
|
rdoc
|
97
|
-
sqlite3
|
98
100
|
|
99
101
|
BUNDLED WITH
|
100
|
-
2.
|
102
|
+
2.5.22
|
data/README.md
CHANGED
@@ -19,48 +19,38 @@ Globalize is not very actively maintained. Pull Requests are welcome, especially
|
|
19
19
|
|
20
20
|
## Requirements
|
21
21
|
|
22
|
-
* ActiveRecord >=
|
22
|
+
* ActiveRecord >= 7.0 (see below for installation with older ActiveRecord)
|
23
23
|
* I18n
|
24
24
|
|
25
25
|
## Installation
|
26
26
|
|
27
|
-
To install the ActiveRecord
|
27
|
+
To install the ActiveRecord 7.x compatible version of Globalize with its default setup, just use:
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
gem install globalize
|
31
31
|
```
|
32
32
|
|
33
|
-
When using
|
33
|
+
When using Bundler, put this in your Gemfile:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
gem
|
36
|
+
gem "globalize", "~> 7.0"
|
37
37
|
```
|
38
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
|
39
|
+
Please help us by letting us know what works, and what doesn't, when using pre-release code. To use a pre-release, put this in your Gemfile:
|
42
40
|
|
43
41
|
```ruby
|
44
|
-
gem
|
45
|
-
gem 'activemodel-serializers-xml'
|
42
|
+
gem "globalize", git: "https://github.com/globalize/globalize", branch: "main"
|
46
43
|
```
|
47
44
|
|
48
|
-
|
45
|
+
## Older ActiveRecord
|
46
|
+
* Use Version 6.3 or lower
|
47
|
+
|
48
|
+
ActiveRecord 4.2 to 6.1:
|
49
49
|
|
50
50
|
```ruby
|
51
|
-
gem
|
51
|
+
gem "globalize", "~> 6.3"
|
52
52
|
```
|
53
53
|
|
54
|
-
To use the version of globalize for ActiveRecord 3.1 or 3.2, specify:
|
55
|
-
|
56
|
-
````ruby
|
57
|
-
gem 'globalize', '~> 3.1.0'
|
58
|
-
````
|
59
|
-
|
60
|
-
(If you are using ActiveRecord 3.0, use version 3.0: `gem 'globalize', '3.0.4'`.)
|
61
|
-
|
62
|
-
The [`3-1-stable` branch](https://github.com/globalize/globalize/tree/3-1-stable) of this repository corresponds to the latest ActiveRecord 3 version of globalize. Note that `globalize3` has been deprecated and you are encouraged to update your Gemfile accordingly.
|
63
|
-
|
64
54
|
## Model translations
|
65
55
|
|
66
56
|
Model translations allow you to translate your models' attribute values. E.g.
|
@@ -84,7 +74,7 @@ post.title # => גלובאלייז2 שולט!
|
|
84
74
|
You can also set translations with mass-assignment by specifying the locale:
|
85
75
|
|
86
76
|
```ruby
|
87
|
-
post.attributes = { title:
|
77
|
+
post.attributes = { title: "גלובאלייז2 שולט!", locale: :he }
|
88
78
|
```
|
89
79
|
|
90
80
|
In order to make this work, you'll need to add the appropriate translation tables.
|
@@ -131,7 +121,7 @@ class CreatePosts < ActiveRecord::Migration
|
|
131
121
|
reversible do |dir|
|
132
122
|
dir.up do
|
133
123
|
Post.create_translation_table! :title => :string,
|
134
|
-
:text => {:type => :text, :null => false, :default =>
|
124
|
+
:text => {:type => :text, :null => false, :default => "abc"}
|
135
125
|
end
|
136
126
|
|
137
127
|
dir.down do
|
@@ -294,15 +284,15 @@ end
|
|
294
284
|
|
295
285
|
puts post.translations.inspect
|
296
286
|
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
297
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
287
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>]
|
298
288
|
|
299
289
|
I18n.locale = :en
|
300
|
-
post.title # =>
|
301
|
-
post.name # =>
|
290
|
+
post.title # => "Globalize rocks!"
|
291
|
+
post.name # => "Globalize"
|
302
292
|
|
303
293
|
I18n.locale = :nl
|
304
|
-
post.title # =>
|
305
|
-
post.name # =>
|
294
|
+
post.title # => ""
|
295
|
+
post.name # => "Globalize"
|
306
296
|
```
|
307
297
|
|
308
298
|
```ruby
|
@@ -312,15 +302,15 @@ end
|
|
312
302
|
|
313
303
|
puts post.translations.inspect
|
314
304
|
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
315
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
305
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>]
|
316
306
|
|
317
307
|
I18n.locale = :en
|
318
|
-
post.title # =>
|
319
|
-
post.name # =>
|
308
|
+
post.title # => "Globalize rocks!"
|
309
|
+
post.name # => "Globalize"
|
320
310
|
|
321
311
|
I18n.locale = :nl
|
322
|
-
post.title # =>
|
323
|
-
post.name # =>
|
312
|
+
post.title # => "Globalize rocks!"
|
313
|
+
post.name # => "Globalize"
|
324
314
|
```
|
325
315
|
|
326
316
|
## Fallback locales to each other
|
@@ -335,15 +325,15 @@ end
|
|
335
325
|
Globalize.fallbacks = {:en => [:en, :pl], :pl => [:pl, :en]}
|
336
326
|
|
337
327
|
I18n.locale = :en
|
338
|
-
en_post = Post.create(:title =>
|
328
|
+
en_post = Post.create(:title => "en_title")
|
339
329
|
|
340
330
|
I18n.locale = :pl
|
341
|
-
pl_post = Post.create(:title =>
|
342
|
-
en_post.title # =>
|
331
|
+
pl_post = Post.create(:title => "pl_title")
|
332
|
+
en_post.title # => "en_title"
|
343
333
|
|
344
334
|
I18n.locale = :en
|
345
|
-
en_post.title # =>
|
346
|
-
pl_post.title # =>
|
335
|
+
en_post.title # => "en_title"
|
336
|
+
pl_post.title # => "pl_title"
|
347
337
|
```
|
348
338
|
|
349
339
|
|
@@ -354,19 +344,19 @@ the `with_translations` scope. This will only return records that have a
|
|
354
344
|
translations for the passed in locale.
|
355
345
|
|
356
346
|
```ruby
|
357
|
-
Post.with_translations(
|
347
|
+
Post.with_translations("en")
|
358
348
|
# => [
|
359
349
|
#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
360
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
350
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>
|
361
351
|
]
|
362
352
|
|
363
353
|
Post.with_translations(I18n.locale)
|
364
354
|
# => [
|
365
355
|
#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
366
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
356
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>
|
367
357
|
]
|
368
358
|
|
369
|
-
Post.with_translations(
|
359
|
+
Post.with_translations("de")
|
370
360
|
# => []
|
371
361
|
```
|
372
362
|
|
@@ -401,7 +391,7 @@ post.title
|
|
401
391
|
post.title(:foo => "bar")
|
402
392
|
# SomeError: missing interpolation argument :superlative
|
403
393
|
|
404
|
-
post.title(:superlative =>
|
394
|
+
post.title(:superlative => 'rocks")
|
405
395
|
# #=> "Globalize rocks!"
|
406
396
|
```
|
407
397
|
|
@@ -413,16 +403,16 @@ One of the possible ways to implement it:
|
|
413
403
|
```ruby
|
414
404
|
# inside translated model
|
415
405
|
def cache_key
|
416
|
-
super
|
406
|
+
[super, Globalize.locale.to_s].join("-")
|
417
407
|
end
|
418
408
|
```
|
419
409
|
|
420
410
|
## Thread-safety
|
421
411
|
|
422
412
|
Globalize uses [request_store](https://github.com/steveklabnik/request_store) gem to clean up thread-global variable after every request.
|
423
|
-
RequestStore includes a Railtie that will configure everything properly
|
413
|
+
RequestStore includes a Railtie that will configure everything properly.
|
424
414
|
|
425
|
-
If you're not using Rails, you may need to consult
|
415
|
+
If you're not using Rails, you may need to consult RequestStore's [README](https://github.com/steveklabnik/request_store#no-rails-no-problem) to configure it.
|
426
416
|
|
427
417
|
## Tutorials and articles
|
428
418
|
* [Go Global with Rails and I18n](http://www.sitepoint.com/go-global-rails-i18n/) - introductory article about i18n in Rails (Ilya Bodrov)
|
@@ -430,7 +420,7 @@ If you're not using Rails, you may need to consult a RequestStore's [README](htt
|
|
430
420
|
## Official Globalize extensions
|
431
421
|
|
432
422
|
* [globalize-accessors](https://github.com/globalize/globalize-accessors) - generator of accessor methods for models. *(e.g. title_en, title_cz)*
|
433
|
-
* [globalize-versioning](https://github.com/globalize/globalize-versioning) - versioning support for using Globalize with [`paper_trail`](https://github.com/airblade/paper_trail).
|
423
|
+
* [globalize-versioning](https://github.com/globalize/globalize-versioning) - versioning support for using Globalize with [`paper_trail`](https://github.com/airblade/paper_trail).
|
434
424
|
|
435
425
|
## Alternative solutions
|
436
426
|
|
data/Rakefile
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rdoc/task'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require "bundler/gem_helper"
|
4
|
+
require "rake"
|
5
|
+
require "rake/testtask"
|
6
|
+
require "rdoc/task"
|
7
|
+
|
8
|
+
desc "Default: run unit tests."
|
6
9
|
task :default => :test
|
7
10
|
|
8
|
-
desc
|
11
|
+
desc "Run all tests."
|
9
12
|
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs <<
|
11
|
-
t.pattern =
|
13
|
+
t.libs << "lib"
|
14
|
+
t.pattern = "test/**/*_test.rb"
|
12
15
|
t.verbose = true
|
13
16
|
end
|
14
17
|
|
15
|
-
desc
|
18
|
+
desc "Generate documentation."
|
16
19
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir =
|
18
|
-
rdoc.title =
|
19
|
-
rdoc.options <<
|
20
|
-
rdoc.rdoc_files.include(
|
21
|
-
rdoc.rdoc_files.include(
|
20
|
+
rdoc.rdoc_dir = "rdoc"
|
21
|
+
rdoc.title = "Globalize"
|
22
|
+
rdoc.options << "--line-numbers" << "--inline-source"
|
23
|
+
rdoc.rdoc_files.include("README")
|
24
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
22
25
|
end
|
23
26
|
|
24
27
|
task :load_path do
|
@@ -28,23 +31,23 @@ task :load_path do
|
|
28
31
|
end
|
29
32
|
|
30
33
|
namespace :db do
|
31
|
-
desc
|
34
|
+
desc "Create the database"
|
32
35
|
task :create => :load_path do
|
33
|
-
require
|
36
|
+
require "support/database"
|
34
37
|
|
35
38
|
Globalize::Test::Database.create!
|
36
39
|
end
|
37
40
|
|
38
41
|
desc "Drop the database"
|
39
42
|
task :drop => :load_path do
|
40
|
-
require
|
43
|
+
require "support/database"
|
41
44
|
|
42
45
|
Globalize::Test::Database.drop!
|
43
46
|
end
|
44
47
|
|
45
48
|
desc "Set up the database schema"
|
46
49
|
task :migrate => :load_path do
|
47
|
-
require
|
50
|
+
require "support/database"
|
48
51
|
|
49
52
|
Globalize::Test::Database.migrate!
|
50
53
|
# ActiveRecord::Schema.migrate :up
|
@@ -53,3 +56,5 @@ namespace :db do
|
|
53
56
|
desc "Drop and recreate the database schema"
|
54
57
|
task :reset => [:drop, :create]
|
55
58
|
end
|
59
|
+
|
60
|
+
Bundler::GemHelper.install_tasks(name: "globalize")
|
@@ -5,7 +5,6 @@ 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)
|
9
8
|
|
10
9
|
# Add any extra translatable attributes.
|
11
10
|
attr_names = attr_names.map(&:to_sym)
|
@@ -41,31 +40,21 @@ module Globalize
|
|
41
40
|
end
|
42
41
|
|
43
42
|
begin
|
44
|
-
if
|
45
|
-
|
46
|
-
|
43
|
+
if database_connection_possible?
|
44
|
+
translated_attribute_name_strings = translated_attribute_names.map(&:to_s)
|
45
|
+
# Only ignore columns if they exist. This allows queries to remain as .*
|
46
|
+
# instead of using explicit column names
|
47
|
+
attributes_that_exist = column_names & translated_attribute_name_strings
|
48
|
+
if attributes_that_exist.any?
|
49
|
+
self.ignored_columns += attributes_that_exist
|
50
|
+
reset_column_information
|
51
|
+
end
|
47
52
|
end
|
48
53
|
rescue ::ActiveRecord::NoDatabaseError
|
49
54
|
warn 'Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.'
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
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 Globalize.rails_42? && database_connection_possible?
|
56
|
-
|
57
|
-
if (overlap = attr_names.map(&:to_s) & column_names).present?
|
58
|
-
ActiveSupport::Deprecation.warn(
|
59
|
-
["You have defined one or more translated attributes with names that conflict with column(s) on the model table. ",
|
60
|
-
"Globalize does not support this configuration anymore, remove or rename column(s) on the model table.\n",
|
61
|
-
"Model name (table name): #{model_name} (#{table_name})\n",
|
62
|
-
"Attribute name(s): #{overlap.join(', ')}\n"].join
|
63
|
-
)
|
64
|
-
end
|
65
|
-
rescue ::ActiveRecord::NoDatabaseError
|
66
|
-
warn 'Unable to connect to a database. Globalize skipped checking attributes with conflicting column names.'
|
67
|
-
end
|
68
|
-
|
69
58
|
def apply_globalize_options(options)
|
70
59
|
options[:table_name] ||= "#{table_name.singularize}_translations"
|
71
60
|
options[:foreign_key] ||= class_name.foreign_key
|
@@ -79,7 +68,16 @@ module Globalize
|
|
79
68
|
|
80
69
|
def enable_serializable_attribute(attr_name)
|
81
70
|
serializer = self.globalize_serialized_attributes[attr_name]
|
82
|
-
|
71
|
+
return unless serializer
|
72
|
+
|
73
|
+
if Globalize.rails_7_1?
|
74
|
+
if serializer.is_a?(Array)
|
75
|
+
# this is only needed for ACTIVE_RECORD_71. Rails 7.2 will only accept KW arguments
|
76
|
+
translation_class.send :serialize, attr_name, serializer[0], **serializer[1]
|
77
|
+
else
|
78
|
+
translation_class.send :serialize, attr_name, **serializer
|
79
|
+
end
|
80
|
+
else
|
83
81
|
if defined?(::ActiveRecord::Coders::YAMLColumn) &&
|
84
82
|
serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
|
85
83
|
serializer = serializer.object_class
|
@@ -99,7 +97,7 @@ module Globalize
|
|
99
97
|
|
100
98
|
has_many :translations, :class_name => translation_class.name,
|
101
99
|
:foreign_key => options[:foreign_key],
|
102
|
-
:dependent => :destroy,
|
100
|
+
:dependent => options.fetch(:dependent, :destroy),
|
103
101
|
:extend => HasManyExtensions,
|
104
102
|
:autosave => options[:autosave],
|
105
103
|
:inverse_of => :globalized_model
|
@@ -41,17 +41,8 @@ module Globalize
|
|
41
41
|
self.dirty = {}
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
record.send(:clear_attribute_changes, [name])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
def _reset_attribute name
|
50
|
-
original_value = record.changed_attributes[name]
|
51
|
-
record.send(:clear_attribute_changes, [name])
|
52
|
-
record.send("#{name}=", original_value)
|
53
|
-
record.send(:clear_attribute_changes, [name])
|
54
|
-
end
|
44
|
+
def _reset_attribute name
|
45
|
+
record.send(:clear_attribute_changes, [name])
|
55
46
|
end
|
56
47
|
|
57
48
|
def reset
|
@@ -3,12 +3,6 @@ module Globalize
|
|
3
3
|
module ClassMethods
|
4
4
|
delegate :translated_locales, :set_translations_table_name, :to => :translation_class
|
5
5
|
|
6
|
-
if Globalize.rails_42?
|
7
|
-
def columns_hash
|
8
|
-
super.except(*translated_attribute_names.map(&:to_s))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
6
|
def with_locales(*locales)
|
13
7
|
all.merge translation_class.with_locales(*locales)
|
14
8
|
end
|
@@ -120,7 +114,7 @@ module Globalize
|
|
120
114
|
end
|
121
115
|
|
122
116
|
def define_translations_accessor(name)
|
123
|
-
attribute(name, ::ActiveRecord::Type::Value.new)
|
117
|
+
attribute(name, ::ActiveRecord::Type::Value.new)
|
124
118
|
define_translations_reader(name)
|
125
119
|
define_translations_writer(name)
|
126
120
|
end
|
@@ -128,7 +122,12 @@ module Globalize
|
|
128
122
|
def database_connection_possible?
|
129
123
|
begin
|
130
124
|
# Without a connection tentative, the `connected?` function can responds with a false negative
|
131
|
-
|
125
|
+
if Globalize.rails_7_2?
|
126
|
+
connection = ::ActiveRecord::Base.lease_connection
|
127
|
+
connection.connect!
|
128
|
+
else
|
129
|
+
::ActiveRecord::Base.connection
|
130
|
+
end
|
132
131
|
rescue
|
133
132
|
# Ignore connection fail because in docker build hasn't a database connection
|
134
133
|
nil
|