globalize 3.0.5 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -46,10 +46,7 @@
46
46
 
47
47
  ## 3.1.0 (2014-1-25)
48
48
 
49
- * Backport scope support on uniqueness validation from 4.0, drop support for ActiveRecord < 3.1, fixes [#324](https://github.com/globalize/globalize/issues/324).
50
-
51
- ## 3.0.5 (2015-04-24)
52
- * Now working properly with the squeel library. (thanks [Toru Mori](https://github.com/torumori)). See [#437](https://github.com/globalize/globalize/pull/437)
49
+ * Backport scope support on uniqueness validation from 4.0, drop support for ActiveRecord < 3.1, fixes ([https://github.com/globalize/globalize/issues/324](#324)).
53
50
 
54
51
  ## 3.0.4 (2014-1-8)
55
52
  * Extract all versioning-related code to separate [globalize-versioning](https://github.com/globalize/globalize-versioning) gem.
data/Gemfile.lock CHANGED
@@ -8,15 +8,15 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.21)
12
- activesupport (= 3.2.21)
11
+ activemodel (3.2.16)
12
+ activesupport (= 3.2.16)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.21)
15
- activemodel (= 3.2.21)
16
- activesupport (= 3.2.21)
14
+ activerecord (3.2.16)
15
+ activemodel (= 3.2.16)
16
+ activesupport (= 3.2.16)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.21)
19
+ activesupport (3.2.16)
20
20
  i18n (~> 0.6, >= 0.6.4)
21
21
  multi_json (~> 1.0)
22
22
  arel (3.0.3)
@@ -25,17 +25,18 @@ GEM
25
25
  ffi2-generators (0.1.1)
26
26
  friendly_id (4.0.10.1)
27
27
  activerecord (>= 3.0, < 4.0)
28
- i18n (0.7.0)
29
- metaclass (0.0.4)
30
- minitest (5.5.1)
31
- mocha (1.1.0)
28
+ i18n (0.6.9)
29
+ json (1.8.1)
30
+ metaclass (0.0.1)
31
+ minitest (4.7.5)
32
+ mocha (0.14.0)
32
33
  metaclass (~> 0.0.1)
33
- multi_json (1.11.0)
34
+ multi_json (1.8.2)
34
35
  pathname_local (0.0.2)
35
- power_assert (0.2.3)
36
- rake (10.4.2)
37
- rdoc (4.2.0)
38
- rubysl (2.1.0)
36
+ rake (10.1.1)
37
+ rdoc (4.1.0)
38
+ json (~> 1.4)
39
+ rubysl (2.0.15)
39
40
  rubysl-abbrev (~> 2.0)
40
41
  rubysl-base64 (~> 2.0)
41
42
  rubysl-benchmark (~> 2.0)
@@ -69,7 +70,7 @@ GEM
69
70
  rubysl-io-nonblock (~> 2.0)
70
71
  rubysl-io-wait (~> 2.0)
71
72
  rubysl-ipaddr (~> 2.0)
72
- rubysl-irb (~> 2.1)
73
+ rubysl-irb (~> 2.0)
73
74
  rubysl-logger (~> 2.0)
74
75
  rubysl-mathn (~> 2.0)
75
76
  rubysl-matrix (~> 2.0)
@@ -98,6 +99,7 @@ GEM
98
99
  rubysl-pstore (~> 2.0)
99
100
  rubysl-pty (~> 2.0)
100
101
  rubysl-rational (~> 2.0)
102
+ rubysl-readline (~> 2.0)
101
103
  rubysl-resolv (~> 2.0)
102
104
  rubysl-rexml (~> 2.0)
103
105
  rubysl-rinda (~> 2.0)
@@ -139,14 +141,14 @@ GEM
139
141
  rubysl-csv (2.0.2)
140
142
  rubysl-english (~> 2.0)
141
143
  rubysl-curses (2.0.1)
142
- rubysl-date (2.0.9)
144
+ rubysl-date (2.0.6)
143
145
  rubysl-delegate (2.0.1)
144
146
  rubysl-digest (2.0.3)
145
147
  rubysl-drb (2.0.1)
146
148
  rubysl-e2mmap (2.0.0)
147
149
  rubysl-english (2.0.0)
148
150
  rubysl-enumerator (2.0.0)
149
- rubysl-erb (2.0.2)
151
+ rubysl-erb (2.0.1)
150
152
  rubysl-etc (2.0.3)
151
153
  ffi2-generators (~> 0.1)
152
154
  rubysl-expect (2.0.0)
@@ -164,11 +166,12 @@ GEM
164
166
  rubysl-io-nonblock (2.0.0)
165
167
  rubysl-io-wait (2.0.0)
166
168
  rubysl-ipaddr (2.0.0)
167
- rubysl-irb (2.1.1)
169
+ rubysl-irb (2.0.4)
168
170
  rubysl-e2mmap (~> 2.0)
169
171
  rubysl-mathn (~> 2.0)
172
+ rubysl-readline (~> 2.0)
170
173
  rubysl-thread (~> 2.0)
171
- rubysl-logger (2.1.0)
174
+ rubysl-logger (2.0.0)
172
175
  rubysl-mathn (2.0.0)
173
176
  rubysl-matrix (2.1.0)
174
177
  rubysl-e2mmap (~> 2.0)
@@ -191,21 +194,22 @@ GEM
191
194
  rubysl-observer (2.0.0)
192
195
  rubysl-open-uri (2.0.0)
193
196
  rubysl-open3 (2.0.0)
194
- rubysl-openssl (2.2.1)
197
+ rubysl-openssl (2.0.5)
195
198
  rubysl-optparse (2.0.1)
196
199
  rubysl-shellwords (~> 2.0)
197
200
  rubysl-ostruct (2.0.4)
198
- rubysl-pathname (2.1.0)
199
- rubysl-prettyprint (2.0.3)
201
+ rubysl-pathname (2.0.0)
202
+ rubysl-prettyprint (2.0.2)
200
203
  rubysl-prime (2.0.1)
201
204
  rubysl-profile (2.0.0)
202
205
  rubysl-profiler (2.0.1)
203
206
  rubysl-pstore (2.0.0)
204
- rubysl-pty (2.0.3)
207
+ rubysl-pty (2.0.2)
205
208
  rubysl-rational (2.0.1)
206
- rubysl-resolv (2.1.0)
207
- rubysl-rexml (2.0.4)
208
- rubysl-rinda (2.0.1)
209
+ rubysl-readline (2.0.2)
210
+ rubysl-resolv (2.0.0)
211
+ rubysl-rexml (2.0.2)
212
+ rubysl-rinda (2.0.0)
209
213
  rubysl-rss (2.0.0)
210
214
  rubysl-scanf (2.0.0)
211
215
  rubysl-securerandom (2.0.0)
@@ -216,14 +220,14 @@ GEM
216
220
  rubysl-stringio (2.0.0)
217
221
  rubysl-strscan (2.0.0)
218
222
  rubysl-sync (2.0.0)
219
- rubysl-syslog (2.1.0)
223
+ rubysl-syslog (2.0.1)
220
224
  ffi2-generators (~> 0.1)
221
225
  rubysl-tempfile (2.0.1)
222
226
  rubysl-thread (2.0.2)
223
227
  rubysl-thwait (2.0.0)
224
228
  rubysl-time (2.0.3)
225
229
  rubysl-timeout (2.0.0)
226
- rubysl-tmpdir (2.0.1)
230
+ rubysl-tmpdir (2.0.0)
227
231
  rubysl-tsort (2.0.1)
228
232
  rubysl-un (2.0.0)
229
233
  rubysl-fileutils (~> 2.0)
@@ -232,13 +236,12 @@ GEM
232
236
  rubysl-weakref (2.0.0)
233
237
  rubysl-webrick (2.0.0)
234
238
  rubysl-xmlrpc (2.0.0)
235
- rubysl-yaml (2.1.0)
239
+ rubysl-yaml (2.0.4)
236
240
  rubysl-zlib (2.0.1)
237
- sqlite3 (1.3.10)
238
- test-unit (3.0.9)
239
- power_assert
241
+ sqlite3 (1.3.8)
242
+ test-unit (2.0.0.0)
240
243
  test_declarative (0.0.5)
241
- tzinfo (0.3.43)
244
+ tzinfo (0.3.38)
242
245
 
243
246
  PLATFORMS
244
247
  ruby
@@ -1,3 +1,3 @@
1
1
  module Globalize
2
- Version = '3.0.5'
2
+ Version = '3.1.0'
3
3
  end
@@ -4,48 +4,32 @@ ActiveRecord::Validations::UniquenessValidator.class_eval do
4
4
  def validate_each_with_translations(record, attribute, value)
5
5
  klass = record.class
6
6
  if klass.translates? && klass.translated?(attribute)
7
- if methods.include?(:build_relation) || respond_to?(:build_relation)
8
- finder_class = klass.translation_class
9
- table = finder_class.arel_table
7
+ finder_class = klass.translation_class
8
+ table = finder_class.arel_table
10
9
 
11
- relation = build_relation(finder_class, table, attribute, value).and(table[:locale].eq(Globalize.locale))
12
- relation = relation.and(table[klass.reflect_on_association(:translations).foreign_key].not_eq(record.send(:id))) if record.persisted?
10
+ relation = build_relation(finder_class, table, attribute, value).and(table[:locale].eq(Globalize.locale))
11
+ relation = relation.and(table[klass.reflect_on_association(:translations).foreign_key].not_eq(record.send(:id))) if record.persisted?
13
12
 
14
- # TODO: add scope with translated attributes
15
- if options[:scope]
16
- ActiveRecord::Base.logger.warn("WARNING: Globalize does not currently support `scope` option on uniqueness validation for translated attributes.")
17
- end
18
-
19
- if finder_class.unscoped.where(relation).exists?
20
- record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
21
- end
22
- else
23
- finder_class = klass.translation_class
24
- table = finder_class.unscoped
25
-
26
- table_name = finder_class.quoted_table_name
27
-
28
- if value && klass.serialized_attributes.key?(attribute.to_s)
29
- value = YAML.dump value
30
- end
13
+ translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
14
+ untranslated_scopes = Array(options[:scope]) - translated_scopes
31
15
 
32
- sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
33
-
34
- relation = table.where(sql, *params).where(:locale => Globalize.locale.to_s)
35
-
36
- Array.wrap(options[:scope]).each do |scope_item|
37
- scope_value = record.send(scope_item)
38
- relation = relation.where(scope_item => scope_value)
16
+ untranslated_scopes.each do |scope_item|
17
+ scope_value = record.send(scope_item)
18
+ reflection = klass.reflect_on_association(scope_item)
19
+ if reflection
20
+ scope_value = record.send(reflection.foreign_key)
21
+ scope_item = reflection.foreign_key
39
22
  end
23
+ relation = relation.and(find_finder_class_for(record).arel_table[scope_item].eq(scope_value))
24
+ end
40
25
 
41
- if record.persisted?
42
- fk = klass.reflect_on_association(:translations).options[:foreign_key]
43
- relation = relation.where(finder_class.arel_table[fk].not_eq(record.send(:id)))
44
- end
26
+ translated_scopes.each do |scope_item|
27
+ scope_value = record.send(scope_item)
28
+ relation = relation.and(table[scope_item].eq(scope_value))
29
+ end
45
30
 
46
- if relation.exists?
47
- record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
48
- end
31
+ if klass.unscoped.with_translations.where(relation).exists?
32
+ record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
49
33
  end
50
34
  else
51
35
  validate_each_without_translations(record, attribute, value)
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Sven Fuchs
@@ -14,158 +15,178 @@ authors:
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
- date: 2015-04-23 00:00:00.000000000 Z
18
+ date: 2014-01-25 00:00:00.000000000 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: activerecord
21
22
  requirement: !ruby/object:Gem::Requirement
23
+ none: false
22
24
  requirements:
23
- - - ">="
25
+ - - ! '>='
24
26
  - !ruby/object:Gem::Version
25
- version: 3.0.0
26
- - - "<"
27
+ version: 3.1.0
28
+ - - <
27
29
  - !ruby/object:Gem::Version
28
30
  version: 4.0.0
29
31
  type: :runtime
30
32
  prerelease: false
31
33
  version_requirements: !ruby/object:Gem::Requirement
34
+ none: false
32
35
  requirements:
33
- - - ">="
36
+ - - ! '>='
34
37
  - !ruby/object:Gem::Version
35
- version: 3.0.0
36
- - - "<"
38
+ version: 3.1.0
39
+ - - <
37
40
  - !ruby/object:Gem::Version
38
41
  version: 4.0.0
39
42
  - !ruby/object:Gem::Dependency
40
43
  name: activemodel
41
44
  requirement: !ruby/object:Gem::Requirement
45
+ none: false
42
46
  requirements:
43
- - - ">="
47
+ - - ! '>='
44
48
  - !ruby/object:Gem::Version
45
- version: 3.0.0
46
- - - "<"
49
+ version: 3.1.0
50
+ - - <
47
51
  - !ruby/object:Gem::Version
48
52
  version: 4.0.0
49
53
  type: :runtime
50
54
  prerelease: false
51
55
  version_requirements: !ruby/object:Gem::Requirement
56
+ none: false
52
57
  requirements:
53
- - - ">="
58
+ - - ! '>='
54
59
  - !ruby/object:Gem::Version
55
- version: 3.0.0
56
- - - "<"
60
+ version: 3.1.0
61
+ - - <
57
62
  - !ruby/object:Gem::Version
58
63
  version: 4.0.0
59
64
  - !ruby/object:Gem::Dependency
60
65
  name: database_cleaner
61
66
  requirement: !ruby/object:Gem::Requirement
67
+ none: false
62
68
  requirements:
63
- - - "~>"
69
+ - - ~>
64
70
  - !ruby/object:Gem::Version
65
71
  version: 0.6.0
66
72
  type: :development
67
73
  prerelease: false
68
74
  version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
69
76
  requirements:
70
- - - "~>"
77
+ - - ~>
71
78
  - !ruby/object:Gem::Version
72
79
  version: 0.6.0
73
80
  - !ruby/object:Gem::Dependency
74
81
  name: mocha
75
82
  requirement: !ruby/object:Gem::Requirement
83
+ none: false
76
84
  requirements:
77
- - - ">="
85
+ - - ! '>='
78
86
  - !ruby/object:Gem::Version
79
87
  version: '0'
80
88
  type: :development
81
89
  prerelease: false
82
90
  version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
83
92
  requirements:
84
- - - ">="
93
+ - - ! '>='
85
94
  - !ruby/object:Gem::Version
86
95
  version: '0'
87
96
  - !ruby/object:Gem::Dependency
88
97
  name: pathname_local
89
98
  requirement: !ruby/object:Gem::Requirement
99
+ none: false
90
100
  requirements:
91
- - - ">="
101
+ - - ! '>='
92
102
  - !ruby/object:Gem::Version
93
103
  version: '0'
94
104
  type: :development
95
105
  prerelease: false
96
106
  version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
97
108
  requirements:
98
- - - ">="
109
+ - - ! '>='
99
110
  - !ruby/object:Gem::Version
100
111
  version: '0'
101
112
  - !ruby/object:Gem::Dependency
102
113
  name: test_declarative
103
114
  requirement: !ruby/object:Gem::Requirement
115
+ none: false
104
116
  requirements:
105
- - - ">="
117
+ - - ! '>='
106
118
  - !ruby/object:Gem::Version
107
119
  version: '0'
108
120
  type: :development
109
121
  prerelease: false
110
122
  version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
111
124
  requirements:
112
- - - ">="
125
+ - - ! '>='
113
126
  - !ruby/object:Gem::Version
114
127
  version: '0'
115
128
  - !ruby/object:Gem::Dependency
116
129
  name: friendly_id
117
130
  requirement: !ruby/object:Gem::Requirement
131
+ none: false
118
132
  requirements:
119
- - - ">="
133
+ - - ! '>='
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0'
122
136
  type: :development
123
137
  prerelease: false
124
138
  version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
125
140
  requirements:
126
- - - ">="
141
+ - - ! '>='
127
142
  - !ruby/object:Gem::Version
128
143
  version: '0'
129
144
  - !ruby/object:Gem::Dependency
130
145
  name: sqlite3
131
146
  requirement: !ruby/object:Gem::Requirement
147
+ none: false
132
148
  requirements:
133
- - - ">="
149
+ - - ! '>='
134
150
  - !ruby/object:Gem::Version
135
151
  version: '0'
136
152
  type: :development
137
153
  prerelease: false
138
154
  version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
139
156
  requirements:
140
- - - ">="
157
+ - - ! '>='
141
158
  - !ruby/object:Gem::Version
142
159
  version: '0'
143
160
  - !ruby/object:Gem::Dependency
144
161
  name: rake
145
162
  requirement: !ruby/object:Gem::Requirement
163
+ none: false
146
164
  requirements:
147
- - - ">="
165
+ - - ! '>='
148
166
  - !ruby/object:Gem::Version
149
167
  version: '0'
150
168
  type: :development
151
169
  prerelease: false
152
170
  version_requirements: !ruby/object:Gem::Requirement
171
+ none: false
153
172
  requirements:
154
- - - ">="
173
+ - - ! '>='
155
174
  - !ruby/object:Gem::Version
156
175
  version: '0'
157
176
  - !ruby/object:Gem::Dependency
158
177
  name: rdoc
159
178
  requirement: !ruby/object:Gem::Requirement
179
+ none: false
160
180
  requirements:
161
- - - ">="
181
+ - - ! '>='
162
182
  - !ruby/object:Gem::Version
163
183
  version: '0'
164
184
  type: :development
165
185
  prerelease: false
166
186
  version_requirements: !ruby/object:Gem::Requirement
187
+ none: false
167
188
  requirements:
168
- - - ">="
189
+ - - ! '>='
169
190
  - !ruby/object:Gem::Version
170
191
  version: '0'
171
192
  description: Rails I18n de-facto standard library for ActiveRecord model/data translation.
@@ -174,69 +195,76 @@ executables: []
174
195
  extensions: []
175
196
  extra_rdoc_files: []
176
197
  files:
177
- - CHANGELOG.md
178
- - CONTRIBUTING.md
179
- - Gemfile
180
- - Gemfile.lock
181
- - LICENSE
182
- - Rakefile
183
- - globalize.gemspec
184
- - init.rb
185
198
  - lib/globalize.rb
199
+ - lib/patches/active_record/xml_attribute_serializer.rb
200
+ - lib/patches/active_record/uniqueness_validator.rb
201
+ - lib/patches/active_record/query_method.rb
202
+ - lib/patches/i18n/interpolate.rb
186
203
  - lib/globalize/active_record.rb
187
- - lib/globalize/active_record/act_macro.rb
188
204
  - lib/globalize/active_record/adapter.rb
189
- - lib/globalize/active_record/attributes.rb
190
- - lib/globalize/active_record/class_methods.rb
191
- - lib/globalize/active_record/exceptions.rb
192
- - lib/globalize/active_record/instance_methods.rb
193
- - lib/globalize/active_record/migration.rb
194
205
  - lib/globalize/active_record/query_methods.rb
206
+ - lib/globalize/active_record/migration.rb
207
+ - lib/globalize/active_record/act_macro.rb
195
208
  - lib/globalize/active_record/translation.rb
196
- - lib/globalize/interpolation.rb
209
+ - lib/globalize/active_record/instance_methods.rb
210
+ - lib/globalize/active_record/class_methods.rb
211
+ - lib/globalize/active_record/exceptions.rb
212
+ - lib/globalize/active_record/attributes.rb
197
213
  - lib/globalize/version.rb
198
- - lib/i18n/missing_translations_log_handler.rb
214
+ - lib/globalize/interpolation.rb
199
215
  - lib/i18n/missing_translations_raise_handler.rb
200
- - lib/patches/active_record/query_method.rb
201
- - lib/patches/active_record/uniqueness_validator.rb
202
- - lib/patches/active_record/xml_attribute_serializer.rb
203
- - lib/patches/i18n/interpolate.rb
204
- - readme.md
216
+ - lib/i18n/missing_translations_log_handler.rb
217
+ - CONTRIBUTING.md
218
+ - Rakefile
219
+ - LICENSE
220
+ - CHANGELOG.md
221
+ - Gemfile
222
+ - Gemfile.lock
205
223
  homepage: https://github.com/globalize/globalize
206
224
  licenses:
207
225
  - MIT
208
- metadata: {}
209
- post_install_message: |2+
226
+ post_install_message: ! '
210
227
 
211
228
  Globalize has extracted versioning support to a separate gem named
229
+
212
230
  globalize-versioning. If you are using versioning (with paper_trail
231
+
213
232
  or any other versioning gem), please add the line
214
- "gem 'globalize-versioning'" to your Gemfile and go to the github
233
+
234
+ "gem ''globalize-versioning''" to your Gemfile and go to the github
235
+
215
236
  page at globalize/globalize-versioning if you encounter any problems.
216
237
 
238
+
217
239
  Note that the globalize-versioning gem does not delegate versions to
240
+
218
241
  the translation table, so you will have to update your syntax to
242
+
219
243
  the form: `post.translation.versions`. See the globalize-versioning
244
+
220
245
  readme for details.
221
246
 
247
+
248
+ '
222
249
  rdoc_options: []
223
250
  require_paths:
224
251
  - lib
225
252
  required_ruby_version: !ruby/object:Gem::Requirement
253
+ none: false
226
254
  requirements:
227
- - - ">="
255
+ - - ! '>='
228
256
  - !ruby/object:Gem::Version
229
257
  version: '0'
230
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
+ none: false
231
260
  requirements:
232
- - - ">="
261
+ - - ! '>='
233
262
  - !ruby/object:Gem::Version
234
263
  version: '0'
235
264
  requirements: []
236
265
  rubyforge_project:
237
- rubygems_version: 2.4.6
266
+ rubygems_version: 1.8.23
238
267
  signing_key:
239
- specification_version: 4
268
+ specification_version: 3
240
269
  summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
241
270
  test_files: []
242
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: ece7db7c7ff689c0abebb00006d1fb5602e2ab7f
4
- data.tar.gz: 68e728cdb2c0d847fc3b57e9e910288af2045f25
5
- SHA512:
6
- metadata.gz: a86baab1b896f424cd6406928676f191d6ae5996c47c596a5c24892240d9a0f496d0275c0d965a52918ea93bb4064aa08a2e08bfc9f21bb038fcf4e5c6fa5282
7
- data.tar.gz: 12d69809f2783da9f9079001b748e449bc2718b57fe814b4661a633c9a7c27ad13503b64035644dc076e88828d77bf841aad1fa003b7a297859eb0df6f90a8de
data/globalize.gemspec DELETED
@@ -1,54 +0,0 @@
1
- require File.expand_path('../lib/globalize/version', __FILE__)
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'globalize'
5
- s.version = Globalize::Version
6
- s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Clemens Kofler', 'John-Paul Bader', 'Tomasz Stachewicz', 'Philip Arndt', 'Chris Salzberg']
7
- s.email = 'nobody@globalize-rails.org'
8
- s.homepage = 'https://github.com/globalize/globalize'
9
- s.summary = 'Rails I18n de-facto standard library for ActiveRecord model/data translation'
10
- s.description = "#{s.summary}."
11
- s.license = "MIT"
12
-
13
- s.files = Dir['{lib/**/*,[A-Z]*}']
14
- s.platform = Gem::Platform::RUBY
15
- s.require_path = 'lib'
16
-
17
- if ENV['RAILS_3_0']
18
- s.add_dependency 'activerecord', '~> 3.0.0'
19
- s.add_dependency 'activemodel', '~> 3.0.0'
20
- elsif ENV['RAILS_3_1']
21
- s.add_dependency 'activerecord', '~> 3.1.0'
22
- s.add_dependency 'activemodel', '~> 3.1.0'
23
- elsif ENV['RAILS_3_2']
24
- s.add_dependency 'activerecord', '~> 3.2.0'
25
- s.add_dependency 'activemodel', '~> 3.2.0'
26
- else
27
- # normal case
28
- s.add_dependency 'activerecord', '>= 3.0.0', '< 4.0.0'
29
- s.add_dependency 'activemodel', '>= 3.0.0', '< 4.0.0'
30
- end
31
-
32
- s.add_development_dependency 'database_cleaner', '~> 0.6.0'
33
- s.add_development_dependency 'mocha'
34
- s.add_development_dependency 'pathname_local'
35
- s.add_development_dependency 'test_declarative'
36
- s.add_development_dependency 'friendly_id'
37
- s.add_development_dependency 'sqlite3'
38
- s.add_development_dependency 'rake'
39
- s.add_development_dependency 'rdoc'
40
- s.post_install_message = <<-END
41
-
42
- Globalize has extracted versioning support to a separate gem named
43
- globalize-versioning. If you are using versioning (with paper_trail
44
- or any other versioning gem), please add the line
45
- "gem 'globalize-versioning'" to your Gemfile and go to the github
46
- page at globalize/globalize-versioning if you encounter any problems.
47
-
48
- Note that the globalize-versioning gem does not delegate versions to
49
- the translation table, so you will have to update your syntax to
50
- the form: `post.translation.versions`. See the globalize-versioning
51
- readme for details.
52
-
53
- END
54
- end
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'globalize'
data/readme.md DELETED
@@ -1,312 +0,0 @@
1
- # Globalize [![Build Status](https://travis-ci.org/globalize/globalize.png?branch=3-0-stable)](https://travis-ci.org/globalize/globalize)
2
-
3
- Globalize builds on the [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
4
- to add model translations to ActiveRecord models.
5
-
6
- ## Requirements
7
-
8
- * ActiveRecord > 4.0.0 (see below for installation with ActiveRecord 3.x)
9
- * I18n
10
-
11
- ## Installation
12
-
13
- To install the ActiveRecord 4.x compatible version of Globalize with its default setup, just use:
14
-
15
- ```ruby
16
- gem install globalize
17
- ```
18
-
19
- When using bundler put this in your Gemfile:
20
-
21
- ```ruby
22
- gem 'globalize', '~> 4.0.0'
23
- ```
24
-
25
- To use the version of globalize for ActiveRecord 3.1 or 3.2, specify:
26
-
27
- ````ruby
28
- gem 'globalize', '~> 3.1.0'
29
- ````
30
-
31
- (If you are using ActiveRecord 3.0, use version 3.0: `gem 'globalize', '3.0.4'`.)
32
-
33
- 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.
34
-
35
- ## Model translations
36
-
37
- Model translations allow you to translate your models' attribute values. E.g.
38
-
39
- ```ruby
40
- class Post < ActiveRecord::Base
41
- translates :title, :text
42
- end
43
- ```
44
-
45
- Allows you to translate the attributes :title and :text per locale:
46
-
47
- ```ruby
48
- I18n.locale = :en
49
- post.title # => Globalize rocks!
50
-
51
- I18n.locale = :he
52
- post.title # => גלובאלייז2 שולט!
53
- ```
54
-
55
- In order to make this work, you'll need to add the appropriate translation tables.
56
- Globalize comes with a handy helper method to help you do this.
57
- It's called `create_translation_table!`. Here's an example:
58
-
59
- _Note that your migrations can use `create_translation_table!` and `drop_translation_table!`
60
- only inside the `up` and `down` instance methods, respectively. You cannot use `create_translation_table!`
61
- and `drop_translation_table!` inside the `change` instance method in Rails >= 3.1.0._
62
-
63
- ### Rails 3.0
64
-
65
- ```ruby
66
- class CreatePosts < ActiveRecord::Migration
67
- def self.up
68
- create_table :posts do |t|
69
- t.timestamps
70
- end
71
- Post.create_translation_table! :title => :string, :text => :text
72
- end
73
- def self.down
74
- drop_table :posts
75
- Post.drop_translation_table!
76
- end
77
- end
78
- ```
79
-
80
- ### Rails >= 3.1.0
81
-
82
- ***Do not use the `change` method, use `up` and `down`!***
83
-
84
- ```ruby
85
- class CreatePosts < ActiveRecord::Migration
86
- def up
87
- create_table :posts do |t|
88
- t.timestamps
89
- end
90
- Post.create_translation_table! :title => :string, :text => :text
91
- end
92
- def down
93
- drop_table :posts
94
- Post.drop_translation_table!
95
- end
96
- end
97
- ```
98
-
99
- Also, you can pass options for specific columns. Here’s an example:
100
-
101
- ```ruby
102
- class CreatePosts < ActiveRecord::Migration
103
- def up
104
- create_table :posts do |t|
105
- t.timestamps
106
- end
107
- Post.create_translation_table! :title => :string,
108
- :text => {:type => :text, :null => false, :default => 'abc'}
109
- end
110
- def down
111
- drop_table :posts
112
- Post.drop_translation_table!
113
- end
114
- end
115
- ```
116
-
117
- Note that the ActiveRecord model `Post` must already exist and have a `translates`
118
- directive listing the translated fields.
119
-
120
- ## Migrating existing data to and from the translated version
121
-
122
- As well as creating a translation table, you can also use `create_translation_table!`
123
- to migrate across any existing data to the default locale. This can also operate
124
- in reverse to restore any translations from the default locale back to the model
125
- when you don't want to use a translation table anymore using `drop_translation_table!`
126
-
127
- This feature makes use of `untranslated_attributes` which allows access to the
128
- model's attributes as they were before the translation was applied. Here's an
129
- example (which assumes you already have a model called `Post` and its table
130
- exists):
131
-
132
- ```ruby
133
- class TranslatePosts < ActiveRecord::Migration
134
- def self.up
135
- Post.create_translation_table!({
136
- :title => :string,
137
- :text => :text
138
- }, {
139
- :migrate_data => true
140
- })
141
- end
142
-
143
- def self.down
144
- Post.drop_translation_table! :migrate_data => true
145
- end
146
- end
147
- ```
148
-
149
- NOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.
150
-
151
- ## Versioning with Globalize
152
-
153
- See the [globalize-versioning](https://github.com/globalize/globalize-versioning) gem.
154
-
155
- ## I18n fallbacks for empty translations
156
-
157
- It is possible to enable fallbacks for empty translations. It will depend on the
158
- configuration setting you have set for I18n translations in your Rails config.
159
-
160
- You can enable them by adding the next line to `config/application.rb` (or only
161
- `config/environments/production.rb` if you only want them in production)
162
-
163
- ```ruby
164
- config.i18n.fallbacks = true
165
- ```
166
-
167
- By default, globalize will only use fallbacks when your translation model does
168
- not exist or the translation value for the item you've requested is `nil`.
169
- However it is possible to also use fallbacks for `blank` translations by adding
170
- `:fallbacks_for_empty_translations => true` to the `translates` method.
171
-
172
- ```ruby
173
- class Post < ActiveRecord::Base
174
- translates :title, :name
175
- end
176
-
177
- puts post.translations.inspect
178
- # => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
179
- #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
180
-
181
- I18n.locale = :en
182
- post.title # => 'Globalize rocks!'
183
- post.name # => 'Globalize'
184
-
185
- I18n.locale = :nl
186
- post.title # => ''
187
- post.name # => 'Globalize'
188
- ```
189
-
190
- ```ruby
191
- class Post < ActiveRecord::Base
192
- translates :title, :name, :fallbacks_for_empty_translations => true
193
- end
194
-
195
- puts post.translations.inspect
196
- # => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
197
- #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
198
-
199
- I18n.locale = :en
200
- post.title # => 'Globalize rocks!'
201
- post.name # => 'Globalize'
202
-
203
- I18n.locale = :nl
204
- post.title # => 'Globalize rocks!'
205
- post.name # => 'Globalize'
206
- ```
207
-
208
- ## Fallback locales to each other
209
-
210
- It is possible to setup locales to fallback to each other.
211
-
212
- ```ruby
213
- class Post < ActiveRecord::Base
214
- translates :title, :name
215
- end
216
-
217
- Globalize.fallbacks = {:en => [:en, :pl], :pl => [:pl, :en]}
218
-
219
- I18n.locale = :en
220
- en_post = Post.create(:title => 'en_title')
221
-
222
- I18n.locale = :pl
223
- pl_post = Post.create(:title => 'pl_title')
224
- en_post.title # => 'en_title'
225
-
226
- I18n.locale = :en
227
- en_post.title # => 'en_title'
228
- pl_post.title # => 'pl_title'
229
- ```
230
-
231
-
232
- ## Scoping objects by those with translations
233
-
234
- To only return objects that have a translation for the given locale we can use
235
- the `with_translations` scope. This will only return records that have a
236
- translations for the passed in locale.
237
-
238
- ```ruby
239
- Post.with_translations('en')
240
- # => [
241
- #<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
242
- #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>
243
- ]
244
-
245
- Post.with_translations(I18n.locale)
246
- # => [
247
- #<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
248
- #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>
249
- ]
250
-
251
- Post.with_translations('de')
252
- # => []
253
- ```
254
-
255
- ## Show different languages
256
-
257
- In views, if there is content from different locales that you wish to display,
258
- you should use the `with_locale` option with a block, as below:
259
-
260
- ```erb
261
- <% Globalize.with_locale(:en) do %>
262
- <%= render "my_translated_partial" %>
263
- <% end %>
264
- ```
265
-
266
- Your partial will now be rendered with the `:en` locale set as the current locale.
267
-
268
- ## Interpolation
269
-
270
- Globalize supports interpolation in a similar manner to I18n.
271
-
272
- ```ruby
273
- class Post < ActiveRecord::Base
274
- translates :title
275
- end
276
-
277
- I18n.locale = :en
278
- post.title = "Globalize %{superlative}!"
279
-
280
- post.title
281
- # #=> "Globalize %{superlative}!"
282
-
283
- post.title(:foo => "bar")
284
- # SomeError: missing interpolation argument :superlative
285
-
286
- post.title(:superlative => "rocks")
287
- # #=> "Globalize rocks!"
288
- ```
289
-
290
- ## Official Globalize extensions
291
-
292
- * [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.
293
- * [globalize-versioning](https://github.com/globalize/globalize-versioning) - Versioning support for using Globalize with [`paper_trail`](https://github.com/airblade/paper_trail).
294
-
295
- ## Alternative Solutions
296
-
297
- * [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
298
- * [TranslatableColumns](http://github.com/iain/translatable_columns) - have multiple languages of the same attribute in a model (Iain Hecker)
299
- * [Traco](https://github.com/barsoom/traco) - A newer take on using multiple columns in the same model (Barsoom)
300
- * [localized_record](http://github.com/glennpow/localized_record) - allows records to have localized attributes without any modifications to the database (Glenn Powell)
301
- * [model_translations](http://github.com/janne/model_translations) - Minimal implementation of Globalize2 style model translations (Jan Andersson)
302
- * [hstore_translate](http://github.com/robworley/hstore_translate) - Rails I18n library for ActiveRecord model/data translation using PostgreSQL's hstore datatype (Rob Worley)
303
-
304
- ## Related solutions
305
-
306
- * [globalize2_versioning](http://github.com/joshmh/globalize2_versioning) - acts_as_versioned style versioning for globalize2 (Joshua Harvey)
307
- * [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)
308
- * [globalize2 Demo App](http://github.com/svenfuchs/globalize2-demo) - demo application for globalize2 (Sven Fuchs)
309
- * [migrate_from_globalize1](http://gist.github.com/120867) - migrate model translations from Globalize1 to globalize2 (Tomasz Stachewicz)
310
- * [easy_globalize2_accessors](http://github.com/astropanic/easy_globalize2_accessors) - easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)
311
- * [globalize2-easy-translate](http://github.com/bsamman/globalize2-easy-translate) - adds methods to easily access or set translated attributes to your model (bsamman)
312
- * [batch_translations](http://github.com/rilla/batch_translations) - allow saving multiple globalize2 translations in the same request (Jose Alvarez Rilla)