globalize 5.3.1 → 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 +14 -9
- data/CHANGELOG.md +34 -0
- data/CONTRIBUTING.md +5 -7
- data/Gemfile +25 -0
- data/Gemfile.lock +102 -0
- data/README.md +43 -48
- data/Rakefile +22 -17
- data/lib/globalize/active_record/act_macro.rb +22 -22
- data/lib/globalize/active_record/adapter_dirty.rb +24 -3
- data/lib/globalize/active_record/class_methods.rb +20 -7
- data/lib/globalize/active_record/instance_methods.rb +38 -30
- data/lib/globalize/active_record/migration.rb +4 -3
- data/lib/globalize/active_record/translated_attributes_query.rb +0 -17
- data/lib/globalize/version.rb +1 -1
- data/lib/globalize.rb +18 -8
- data/lib/patches/active_record/{rails5_1 → rails6_1}/serialization.rb +2 -2
- data/lib/patches/active_record/{rails5_1 → rails6_1}/uniqueness_validator.rb +1 -1
- 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 +12 -9
- data/lib/patches/active_record/serialization.rb +6 -4
- data/lib/patches/active_record/uniqueness_validator.rb +1 -7
- data/lib/patches/active_support/inflections.rb +12 -0
- metadata +41 -39
- data/docker-compose.yml +0 -22
- data/globalize.gemspec +0 -32
- 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
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,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
RAILS_VERSIONS = %w[
|
|
4
|
-
|
|
5
|
-
5.1.6
|
|
6
|
-
5.2.1
|
|
4
|
+
7.0.1
|
|
7
5
|
]
|
|
8
6
|
|
|
9
7
|
RAILS_VERSIONS.each do |version|
|
|
@@ -11,21 +9,28 @@ RAILS_VERSIONS.each do |version|
|
|
|
11
9
|
gem 'activemodel', version
|
|
12
10
|
gem 'activerecord', version
|
|
13
11
|
|
|
14
|
-
platforms :rbx
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
gem 'sqlite3', '~> 1.4', platforms: [:ruby, :rbx]
|
|
13
|
+
|
|
14
|
+
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
|
15
|
+
group :postgres, :postgresql do
|
|
16
|
+
if version =~ /^4/
|
|
17
|
+
gem 'pg', '< 1.0', platforms: [:ruby, :rbx]
|
|
18
|
+
else
|
|
19
|
+
gem 'pg', '~> 1.1', platforms: [:ruby, :rbx]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
platforms :jruby do
|
|
20
|
-
if !ENV['
|
|
25
|
+
if !ENV['CI'] || ENV['DB'] == 'sqlite3'
|
|
21
26
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
|
|
22
27
|
end
|
|
23
28
|
|
|
24
|
-
if !ENV['
|
|
29
|
+
if !ENV['CI'] || ENV['DB'] == 'mysql'
|
|
25
30
|
gem 'activerecord-jdbcmysql-adapter', '~> 1'
|
|
26
31
|
end
|
|
27
32
|
|
|
28
|
-
if !ENV['
|
|
33
|
+
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
|
29
34
|
gem 'activerecord-jdbcpostgresql-adapter', '~> 1'
|
|
30
35
|
end
|
|
31
36
|
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
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
|
+
|
|
10
|
+
## 6.3.0 (2023-10-22)
|
|
11
|
+
|
|
12
|
+
* Support ruby 3.2 rails 7.1 [#810](https://github.com/globalize/globalize/pull/810) by [Shinichi Maeshima](https://github.com/willnet)
|
|
13
|
+
|
|
14
|
+
## 6.2.1 (2022-05-24)
|
|
15
|
+
|
|
16
|
+
* Changed serialize method in Rails 6.1.0+ [#798](https://github.com/globalize/globalize/pull/798) by [Alex](https://github.com/oivoodoo)
|
|
17
|
+
|
|
18
|
+
## 6.2.0 (2022-05-24)
|
|
19
|
+
|
|
20
|
+
* Fix asset precompile in docker build workflow [#799](https://github.com/globalize/globalize/pull/799) by [Diefferson Koderer Môro](https://github.com/djpremier)
|
|
21
|
+
|
|
22
|
+
## 6.1.0 (2022-02-25)
|
|
23
|
+
|
|
24
|
+
* Patch ActiveSupport in Rails 7.0.0+ [#792](https://github.com/globalize/globalize/pull/792) by [Daniel Chan](https://github.com/mynameisdaniel) and [Artis Raugulis](https://github.com/artisr)
|
|
25
|
+
|
|
26
|
+
## 6.0.1 (2021-06-23)
|
|
27
|
+
|
|
28
|
+
* Fix errors with Rails 6.1 and Ruby 3.0 [#778](https://github.com/globalize/globalize/pull/778) by [Andrew White](https://github.com/pixeltrix)
|
|
29
|
+
* Track `saved_changes` for Rails 5.1 and above [#780](https://github.com/globalize/globalize/pull/780) by [Peter Postma](https://github.com/ppostma)
|
|
30
|
+
|
|
31
|
+
## 6.0.0 (2021-01-11)
|
|
32
|
+
|
|
33
|
+
* Add `create_source_columns` option for migrations. [#715](https://github.com/globalize/globalize/pull/715) by [IlyasValiullov](https://github.com/IlyasValiullov)
|
|
34
|
+
* Autosave is now configurable, but defaults to false. [#736](https://github.com/globalize/globalize/pull/736) by [James Hart](https://github.com/hjhart)
|
|
35
|
+
* Fix foreign keys translation. [#769](https://github.com/globalize/globalize/pull/769) by [Sergey Tokarenko](https://github.com/stokarenko)
|
|
36
|
+
|
|
3
37
|
## 5.3.1 (2021-01-11)
|
|
4
38
|
|
|
5
39
|
* Fix foreign keys translation. [#773](https://github.com/globalize/globalize/pull/773) by [Sergey Tokarenko](https://github.com/stokarenko)
|
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
|
|
|
@@ -12,15 +12,15 @@ If you also have some idea how to fix the bug, then by all means post a pull req
|
|
|
12
12
|
|
|
13
13
|
Have an idea for a new feature? Great! Keep in mind though that we are trying to cut down on non-core functionality in the Globalize core and push it to separate extensions, such as [globalize-accessors](https://github.com/globalize/globalize-accessors). If you are proposing something like this, we would prefer you to create a separate repository and gem for it.
|
|
14
14
|
|
|
15
|
-
If however your feature would improve the core functionality of Globalize, please do submit a PR, preferably to the `
|
|
15
|
+
If however your feature would improve the core functionality of Globalize, please do submit a PR, preferably to the `main` branch.
|
|
16
16
|
|
|
17
17
|
## Refactoring
|
|
18
18
|
|
|
19
|
-
Have some free time? Help us improve our [code climate score](https://codeclimate.com/github/globalize/globalize) by refactoring the codebase. If the tests still pass and the changes seem reasonable, we will happily merge them. As elsewhere, priority always goes to the Rails/AR 4 series (`
|
|
19
|
+
Have some free time? Help us improve our [code climate score](https://codeclimate.com/github/globalize/globalize) by refactoring the codebase. If the tests still pass and the changes seem reasonable, we will happily merge them. As elsewhere, priority always goes to the Rails/AR 4 series (`main` branch).
|
|
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,9 +32,7 @@ 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
|
-
|
|
36
|
-
|
|
37
|
-
When you submit the pull request, Travis CI will run the [test suite](https://travis-ci.org/globalize/globalize) 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.
|
|
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
|
|
40
38
|
|
data/Gemfile
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
|
+
|
|
5
|
+
# Database Configuration
|
|
6
|
+
if !ENV['CI'] || ENV['DB'] == 'sqlite3'
|
|
7
|
+
gem 'sqlite3', platforms: [:ruby, :rbx]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# have a look at test/support/database.yml which environment variables can be set
|
|
11
|
+
if !ENV['CI'] || ENV['DB'] == 'mysql'
|
|
12
|
+
group :mysql do
|
|
13
|
+
gem 'mysql2', platforms: [:ruby, :rbx]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
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
|
+
|
|
24
|
+
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
|
25
|
+
group :postgres, :postgresql do
|
|
26
|
+
gem 'pg', platforms: [:ruby, :rbx]
|
|
27
|
+
end
|
|
28
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
globalize (7.0.0)
|
|
5
|
+
activemodel (>= 7.0, < 8.1)
|
|
6
|
+
activerecord (>= 7.0, < 8.1)
|
|
7
|
+
activesupport (>= 7.0, < 8.1)
|
|
8
|
+
request_store (~> 1.0)
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
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)
|
|
18
|
+
timeout (>= 0.4.0)
|
|
19
|
+
activesupport (8.0.1)
|
|
20
|
+
base64
|
|
21
|
+
benchmark (>= 0.3)
|
|
22
|
+
bigdecimal
|
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
24
|
+
connection_pool (>= 2.2.5)
|
|
25
|
+
drb
|
|
26
|
+
i18n (>= 1.6, < 2)
|
|
27
|
+
logger (>= 1.4.2)
|
|
28
|
+
minitest (>= 5.1)
|
|
29
|
+
securerandom (>= 0.3)
|
|
30
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
31
|
+
uri (>= 0.13.1)
|
|
32
|
+
ansi (1.5.0)
|
|
33
|
+
appraisal (2.5.0)
|
|
34
|
+
bundler
|
|
35
|
+
rake
|
|
36
|
+
thor (>= 0.14.0)
|
|
37
|
+
base64 (0.2.0)
|
|
38
|
+
benchmark (0.4.0)
|
|
39
|
+
bigdecimal (3.1.8)
|
|
40
|
+
builder (3.3.0)
|
|
41
|
+
coderay (1.1.3)
|
|
42
|
+
concurrent-ruby (1.3.4)
|
|
43
|
+
connection_pool (2.4.1)
|
|
44
|
+
database_cleaner (2.1.0)
|
|
45
|
+
database_cleaner-active_record (>= 2, < 3)
|
|
46
|
+
database_cleaner-active_record (2.2.0)
|
|
47
|
+
activerecord (>= 5.a)
|
|
48
|
+
database_cleaner-core (~> 2.0.0)
|
|
49
|
+
database_cleaner-core (2.0.1)
|
|
50
|
+
date (3.4.1)
|
|
51
|
+
drb (2.2.1)
|
|
52
|
+
i18n (1.14.6)
|
|
53
|
+
concurrent-ruby (~> 1.0)
|
|
54
|
+
logger (1.6.4)
|
|
55
|
+
m (1.6.2)
|
|
56
|
+
method_source (>= 0.6.7)
|
|
57
|
+
rake (>= 0.9.2.2)
|
|
58
|
+
method_source (1.1.0)
|
|
59
|
+
minitest (5.25.4)
|
|
60
|
+
minitest-reporters (1.7.1)
|
|
61
|
+
ansi
|
|
62
|
+
builder
|
|
63
|
+
minitest (>= 5.0)
|
|
64
|
+
ruby-progressbar
|
|
65
|
+
pry (0.15.0)
|
|
66
|
+
coderay (~> 1.1)
|
|
67
|
+
method_source (~> 1.0)
|
|
68
|
+
psych (5.2.2)
|
|
69
|
+
date
|
|
70
|
+
stringio
|
|
71
|
+
rack (3.1.8)
|
|
72
|
+
rake (13.2.1)
|
|
73
|
+
rdoc (6.10.0)
|
|
74
|
+
psych (>= 4.0.0)
|
|
75
|
+
request_store (1.7.0)
|
|
76
|
+
rack (>= 1.4)
|
|
77
|
+
ruby-progressbar (1.13.0)
|
|
78
|
+
securerandom (0.4.1)
|
|
79
|
+
stringio (3.1.2)
|
|
80
|
+
thor (1.3.2)
|
|
81
|
+
timeout (0.4.3)
|
|
82
|
+
tzinfo (2.0.6)
|
|
83
|
+
concurrent-ruby (~> 1.0)
|
|
84
|
+
uri (1.0.2)
|
|
85
|
+
|
|
86
|
+
PLATFORMS
|
|
87
|
+
ruby
|
|
88
|
+
x86_64-linux
|
|
89
|
+
|
|
90
|
+
DEPENDENCIES
|
|
91
|
+
appraisal
|
|
92
|
+
database_cleaner
|
|
93
|
+
globalize!
|
|
94
|
+
m
|
|
95
|
+
minitest
|
|
96
|
+
minitest-reporters
|
|
97
|
+
pry
|
|
98
|
+
rake
|
|
99
|
+
rdoc
|
|
100
|
+
|
|
101
|
+
BUNDLED WITH
|
|
102
|
+
2.5.22
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
[](https://github.com/globalize/globalize/actions) [](https://codeclimate.com/github/globalize/globalize)
|
|
4
4
|
[](https://www.codetriage.com/globalize/globalize)
|
|
5
5
|
|
|
6
6
|
You can chat with us using Gitter:
|
|
@@ -12,50 +12,45 @@ to add model translations to ActiveRecord models.
|
|
|
12
12
|
|
|
13
13
|
In other words, a way to translate actual user-generated content, for example; a single blog post with multiple translations.
|
|
14
14
|
|
|
15
|
+
## Current state of the gem
|
|
16
|
+
|
|
17
|
+
Globalize is not very actively maintained. Pull Requests are welcome, especially for compatibility with new versions of Rails, but none of the maintainers actively use Globalize anymore. If you need a more actively maintained model translation gem, we recommend checking out [Mobility](https://github.com/shioyama/mobility), a natural successor of Globalize created by Chris Salzberg (one of Globalize maintainers) and inspired by the ideas discussed around Globalize. For a more up-to-date discussion of the current situation, see [issue #753](https://github.com/globalize/globalize/issues/753).
|
|
18
|
+
|
|
19
|
+
|
|
15
20
|
## Requirements
|
|
16
21
|
|
|
17
|
-
* ActiveRecord >=
|
|
22
|
+
* ActiveRecord >= 7.0 (see below for installation with older ActiveRecord)
|
|
18
23
|
* I18n
|
|
19
24
|
|
|
20
25
|
## Installation
|
|
21
26
|
|
|
22
|
-
To install the ActiveRecord
|
|
27
|
+
To install the ActiveRecord 7.x compatible version of Globalize with its default setup, just use:
|
|
23
28
|
|
|
24
29
|
```ruby
|
|
25
30
|
gem install globalize
|
|
26
31
|
```
|
|
27
32
|
|
|
28
|
-
When using
|
|
33
|
+
When using Bundler, put this in your Gemfile:
|
|
29
34
|
|
|
30
35
|
```ruby
|
|
31
|
-
gem
|
|
36
|
+
gem "globalize", "~> 7.0"
|
|
32
37
|
```
|
|
33
38
|
|
|
34
|
-
Please help us by letting us know what works, and what doesn't, when using pre-release code.
|
|
35
|
-
|
|
36
|
-
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:
|
|
37
40
|
|
|
38
41
|
```ruby
|
|
39
|
-
gem
|
|
40
|
-
gem 'activemodel-serializers-xml'
|
|
42
|
+
gem "globalize", git: "https://github.com/globalize/globalize", branch: "main"
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
## Older ActiveRecord
|
|
46
|
+
* Use Version 6.3 or lower
|
|
47
|
+
|
|
48
|
+
ActiveRecord 4.2 to 6.1:
|
|
44
49
|
|
|
45
50
|
```ruby
|
|
46
|
-
gem
|
|
51
|
+
gem "globalize", "~> 6.3"
|
|
47
52
|
```
|
|
48
53
|
|
|
49
|
-
To use the version of globalize for ActiveRecord 3.1 or 3.2, specify:
|
|
50
|
-
|
|
51
|
-
````ruby
|
|
52
|
-
gem 'globalize', '~> 3.1.0'
|
|
53
|
-
````
|
|
54
|
-
|
|
55
|
-
(If you are using ActiveRecord 3.0, use version 3.0: `gem 'globalize', '3.0.4'`.)
|
|
56
|
-
|
|
57
|
-
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.
|
|
58
|
-
|
|
59
54
|
## Model translations
|
|
60
55
|
|
|
61
56
|
Model translations allow you to translate your models' attribute values. E.g.
|
|
@@ -79,7 +74,7 @@ post.title # => גלובאלייז2 שולט!
|
|
|
79
74
|
You can also set translations with mass-assignment by specifying the locale:
|
|
80
75
|
|
|
81
76
|
```ruby
|
|
82
|
-
post.attributes = { title:
|
|
77
|
+
post.attributes = { title: "גלובאלייז2 שולט!", locale: :he }
|
|
83
78
|
```
|
|
84
79
|
|
|
85
80
|
In order to make this work, you'll need to add the appropriate translation tables.
|
|
@@ -126,7 +121,7 @@ class CreatePosts < ActiveRecord::Migration
|
|
|
126
121
|
reversible do |dir|
|
|
127
122
|
dir.up do
|
|
128
123
|
Post.create_translation_table! :title => :string,
|
|
129
|
-
:text => {:type => :text, :null => false, :default =>
|
|
124
|
+
:text => {:type => :text, :null => false, :default => "abc"}
|
|
130
125
|
end
|
|
131
126
|
|
|
132
127
|
dir.down do
|
|
@@ -289,15 +284,15 @@ end
|
|
|
289
284
|
|
|
290
285
|
puts post.translations.inspect
|
|
291
286
|
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
|
292
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
|
287
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>]
|
|
293
288
|
|
|
294
289
|
I18n.locale = :en
|
|
295
|
-
post.title # =>
|
|
296
|
-
post.name # =>
|
|
290
|
+
post.title # => "Globalize rocks!"
|
|
291
|
+
post.name # => "Globalize"
|
|
297
292
|
|
|
298
293
|
I18n.locale = :nl
|
|
299
|
-
post.title # =>
|
|
300
|
-
post.name # =>
|
|
294
|
+
post.title # => ""
|
|
295
|
+
post.name # => "Globalize"
|
|
301
296
|
```
|
|
302
297
|
|
|
303
298
|
```ruby
|
|
@@ -307,15 +302,15 @@ end
|
|
|
307
302
|
|
|
308
303
|
puts post.translations.inspect
|
|
309
304
|
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
|
310
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
|
305
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>]
|
|
311
306
|
|
|
312
307
|
I18n.locale = :en
|
|
313
|
-
post.title # =>
|
|
314
|
-
post.name # =>
|
|
308
|
+
post.title # => "Globalize rocks!"
|
|
309
|
+
post.name # => "Globalize"
|
|
315
310
|
|
|
316
311
|
I18n.locale = :nl
|
|
317
|
-
post.title # =>
|
|
318
|
-
post.name # =>
|
|
312
|
+
post.title # => "Globalize rocks!"
|
|
313
|
+
post.name # => "Globalize"
|
|
319
314
|
```
|
|
320
315
|
|
|
321
316
|
## Fallback locales to each other
|
|
@@ -330,15 +325,15 @@ end
|
|
|
330
325
|
Globalize.fallbacks = {:en => [:en, :pl], :pl => [:pl, :en]}
|
|
331
326
|
|
|
332
327
|
I18n.locale = :en
|
|
333
|
-
en_post = Post.create(:title =>
|
|
328
|
+
en_post = Post.create(:title => "en_title")
|
|
334
329
|
|
|
335
330
|
I18n.locale = :pl
|
|
336
|
-
pl_post = Post.create(:title =>
|
|
337
|
-
en_post.title # =>
|
|
331
|
+
pl_post = Post.create(:title => "pl_title")
|
|
332
|
+
en_post.title # => "en_title"
|
|
338
333
|
|
|
339
334
|
I18n.locale = :en
|
|
340
|
-
en_post.title # =>
|
|
341
|
-
pl_post.title # =>
|
|
335
|
+
en_post.title # => "en_title"
|
|
336
|
+
pl_post.title # => "pl_title"
|
|
342
337
|
```
|
|
343
338
|
|
|
344
339
|
|
|
@@ -349,19 +344,19 @@ the `with_translations` scope. This will only return records that have a
|
|
|
349
344
|
translations for the passed in locale.
|
|
350
345
|
|
|
351
346
|
```ruby
|
|
352
|
-
Post.with_translations(
|
|
347
|
+
Post.with_translations("en")
|
|
353
348
|
# => [
|
|
354
349
|
#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
|
355
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
|
350
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>
|
|
356
351
|
]
|
|
357
352
|
|
|
358
353
|
Post.with_translations(I18n.locale)
|
|
359
354
|
# => [
|
|
360
355
|
#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
|
|
361
|
-
#<Post::Translation id: 2, post_id: 1, locale: "nl", title:
|
|
356
|
+
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: "", name: nil>
|
|
362
357
|
]
|
|
363
358
|
|
|
364
|
-
Post.with_translations(
|
|
359
|
+
Post.with_translations("de")
|
|
365
360
|
# => []
|
|
366
361
|
```
|
|
367
362
|
|
|
@@ -396,7 +391,7 @@ post.title
|
|
|
396
391
|
post.title(:foo => "bar")
|
|
397
392
|
# SomeError: missing interpolation argument :superlative
|
|
398
393
|
|
|
399
|
-
post.title(:superlative =>
|
|
394
|
+
post.title(:superlative => 'rocks")
|
|
400
395
|
# #=> "Globalize rocks!"
|
|
401
396
|
```
|
|
402
397
|
|
|
@@ -408,16 +403,16 @@ One of the possible ways to implement it:
|
|
|
408
403
|
```ruby
|
|
409
404
|
# inside translated model
|
|
410
405
|
def cache_key
|
|
411
|
-
super
|
|
406
|
+
[super, Globalize.locale.to_s].join("-")
|
|
412
407
|
end
|
|
413
408
|
```
|
|
414
409
|
|
|
415
410
|
## Thread-safety
|
|
416
411
|
|
|
417
412
|
Globalize uses [request_store](https://github.com/steveklabnik/request_store) gem to clean up thread-global variable after every request.
|
|
418
|
-
RequestStore includes a Railtie that will configure everything properly
|
|
413
|
+
RequestStore includes a Railtie that will configure everything properly.
|
|
419
414
|
|
|
420
|
-
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.
|
|
421
416
|
|
|
422
417
|
## Tutorials and articles
|
|
423
418
|
* [Go Global with Rails and I18n](http://www.sitepoint.com/go-global-rails-i18n/) - introductory article about i18n in Rails (Ilya Bodrov)
|
|
@@ -425,7 +420,7 @@ If you're not using Rails, you may need to consult a RequestStore's [README](htt
|
|
|
425
420
|
## Official Globalize extensions
|
|
426
421
|
|
|
427
422
|
* [globalize-accessors](https://github.com/globalize/globalize-accessors) - generator of accessor methods for models. *(e.g. title_en, title_cz)*
|
|
428
|
-
* [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).
|
|
429
424
|
|
|
430
425
|
## Alternative solutions
|
|
431
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,33 +40,25 @@ 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 ::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.'
|
|
66
|
-
end
|
|
67
|
-
|
|
68
58
|
def apply_globalize_options(options)
|
|
69
59
|
options[:table_name] ||= "#{table_name.singularize}_translations"
|
|
70
60
|
options[:foreign_key] ||= class_name.foreign_key
|
|
61
|
+
options[:autosave] ||= false
|
|
71
62
|
|
|
72
63
|
class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
|
|
73
64
|
self.translated_attribute_names = []
|
|
@@ -77,7 +68,16 @@ module Globalize
|
|
|
77
68
|
|
|
78
69
|
def enable_serializable_attribute(attr_name)
|
|
79
70
|
serializer = self.globalize_serialized_attributes[attr_name]
|
|
80
|
-
|
|
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
|
|
81
81
|
if defined?(::ActiveRecord::Coders::YAMLColumn) &&
|
|
82
82
|
serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
|
|
83
83
|
serializer = serializer.object_class
|
|
@@ -97,9 +97,9 @@ module Globalize
|
|
|
97
97
|
|
|
98
98
|
has_many :translations, :class_name => translation_class.name,
|
|
99
99
|
:foreign_key => options[:foreign_key],
|
|
100
|
-
:dependent => :destroy,
|
|
100
|
+
:dependent => options.fetch(:dependent, :destroy),
|
|
101
101
|
:extend => HasManyExtensions,
|
|
102
|
-
:autosave =>
|
|
102
|
+
:autosave => options[:autosave],
|
|
103
103
|
:inverse_of => :globalized_model
|
|
104
104
|
|
|
105
105
|
after_create :save_translations!
|