globalize 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/lib/globalize.rb +4 -0
- data/lib/globalize/active_record/act_macro.rb +1 -8
- data/lib/globalize/active_record/class_methods.rb +1 -1
- data/lib/globalize/active_record/instance_methods.rb +8 -9
- data/lib/globalize/version.rb +1 -1
- data/lib/patches/active_record/serialization.rb +24 -0
- data/readme.md +11 -0
- metadata +3 -3
- data/init.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f79ee6b19f357cae4c848d662d6f081a6375b8c
|
4
|
+
data.tar.gz: 1f4fe986e59139c19acd2c2eac58b7598213ed85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9894c0da31c4734117700845576c612e24a9c4575fc19370c87f788837ea6bf0968fe46c51d094c9a75d0fc39d1c7204b2b581716a5663a5a82ef901ae12de
|
7
|
+
data.tar.gz: c6ee550b86c3cec2e43443d11791b88a03c0d541cb1791a1b3aed249f664297ca96b0721823322c78ba8a869e4b82508727b70889d8c47b4a83f86caa6505a64
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Globalize Changelog
|
2
2
|
|
3
|
-
## 5.0.
|
3
|
+
## 5.0.1 (2015-02-15)
|
4
|
+
|
5
|
+
* Don't touch table when model is loaded. [#412](https://github.com/globalize/globalize/pull/412)
|
6
|
+
* Remove handling for locale attribute on parent model [#411](https://github.com/globalize/globalize/pull/411) by awesome [Tekin Suleyman](https://github.com/tekin).
|
7
|
+
|
8
|
+
## 5.0.0 (2015-02-03)
|
4
9
|
* Added support for Rails 4.2, but removed support for every previous version of Rails. This is a backward incompatible change, thus the version is now 5.0.0. (thanks [Nico Ritsche](https://github.com/ncri) and others). [#396](https://github.com/globalize/globalize/pull/396).
|
5
10
|
|
6
11
|
## 4.0.3 (2014-11-24)
|
data/Gemfile.lock
CHANGED
data/lib/globalize.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'patches/active_record/xml_attribute_serializer'
|
3
3
|
require 'patches/active_record/query_method'
|
4
|
+
require 'patches/active_record/serialization'
|
4
5
|
require 'patches/active_record/uniqueness_validator'
|
5
6
|
require 'patches/active_record/persistence'
|
6
7
|
|
@@ -77,4 +78,7 @@ module Globalize
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
81
|
+
ActiveRecord::Base.mattr_accessor :globalize_serialized_attributes, instance_writer: false
|
82
|
+
ActiveRecord::Base.globalize_serialized_attributes = {}
|
83
|
+
|
80
84
|
ActiveRecord::Base.extend(Globalize::ActiveRecord::ActMacro)
|
@@ -51,7 +51,7 @@ module Globalize
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def enable_serializable_attribute(attr_name)
|
54
|
-
serializer =
|
54
|
+
serializer = self.globalize_serialized_attributes[attr_name]
|
55
55
|
if serializer.present?
|
56
56
|
if defined?(::ActiveRecord::Coders::YAMLColumn) &&
|
57
57
|
serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
|
@@ -62,13 +62,6 @@ module Globalize
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
def serializer_for_attribute(attr_name)
|
66
|
-
column = self.columns_hash[attr_name.to_s]
|
67
|
-
if column && column.cast_type.is_a?(::ActiveRecord::Type::Serialized)
|
68
|
-
column.cast_type.coder
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
65
|
def setup_translates!(options)
|
73
66
|
apply_globalize_options(options)
|
74
67
|
|
@@ -47,7 +47,7 @@ module Globalize
|
|
47
47
|
klass = self.const_set(:Translation, Class.new(Globalize::ActiveRecord::Translation))
|
48
48
|
end
|
49
49
|
|
50
|
-
klass.belongs_to :globalized_model, :class_name => self.name, :foreign_key => translation_options[:foreign_key]
|
50
|
+
klass.belongs_to :globalized_model, :class_name => self.name, :foreign_key => translation_options[:foreign_key]
|
51
51
|
klass
|
52
52
|
end
|
53
53
|
end
|
@@ -45,9 +45,7 @@ module Globalize
|
|
45
45
|
options = {:translated => true, :locale => nil}.merge(options)
|
46
46
|
return super(name) unless options[:translated]
|
47
47
|
|
48
|
-
if name
|
49
|
-
self.try(:locale).presence || self.translation.locale
|
50
|
-
elsif self.class.translated?(name)
|
48
|
+
if translated?(name)
|
51
49
|
if (value = globalize.fetch(options[:locale] || Globalize.locale, name))
|
52
50
|
value
|
53
51
|
else
|
@@ -66,7 +64,7 @@ module Globalize
|
|
66
64
|
|
67
65
|
def translated_attributes
|
68
66
|
translated_attribute_names.inject({}) do |attributes, name|
|
69
|
-
attributes.merge(name.to_s =>
|
67
|
+
attributes.merge(name.to_s => send(name))
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
@@ -150,7 +148,7 @@ module Globalize
|
|
150
148
|
end
|
151
149
|
|
152
150
|
def save(*)
|
153
|
-
Globalize.with_locale(
|
151
|
+
Globalize.with_locale(translation.locale || I18n.default_locale) do
|
154
152
|
super
|
155
153
|
end
|
156
154
|
end
|
@@ -161,6 +159,10 @@ module Globalize
|
|
161
159
|
globalize.send(:column_for_attribute, name)
|
162
160
|
end
|
163
161
|
|
162
|
+
def cache_key
|
163
|
+
[super, translation.cache_key].join("/")
|
164
|
+
end
|
165
|
+
|
164
166
|
protected
|
165
167
|
|
166
168
|
def each_locale_and_translated_attribute
|
@@ -185,10 +187,7 @@ module Globalize
|
|
185
187
|
def with_given_locale(attributes, &block)
|
186
188
|
attributes.symbolize_keys! if attributes.respond_to?(:symbolize_keys!)
|
187
189
|
|
188
|
-
locale =
|
189
|
-
attributes.try(:delete, :locale)
|
190
|
-
|
191
|
-
if locale
|
190
|
+
if locale = attributes.try(:delete, :locale)
|
192
191
|
Globalize.with_locale(locale, &block)
|
193
192
|
else
|
194
193
|
yield
|
data/lib/globalize/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module AttributeMethods
|
3
|
+
module Serialization
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def serialize_with_globalize(attr_name, class_name_or_coder = Object)
|
8
|
+
serialize_without_globalize(attr_name, class_name_or_coder)
|
9
|
+
|
10
|
+
coder = if class_name_or_coder == ::JSON
|
11
|
+
Coders::JSON
|
12
|
+
elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
|
13
|
+
class_name_or_coder
|
14
|
+
else
|
15
|
+
Coders::YAMLColumn.new(class_name_or_coder)
|
16
|
+
end
|
17
|
+
|
18
|
+
self.globalize_serialized_attributes[attr_name] = coder
|
19
|
+
end
|
20
|
+
alias_method_chain :serialize, :globalize
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/readme.md
CHANGED
@@ -64,6 +64,12 @@ I18n.locale = :he
|
|
64
64
|
post.title # => גלובאלייז2 שולט!
|
65
65
|
```
|
66
66
|
|
67
|
+
You can also set translations with mass-assignment by specifying the locale:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
post.attributes = { title: 'גלובאלייז2 שולט!', locale: :he }
|
71
|
+
```
|
72
|
+
|
67
73
|
In order to make this work, you'll need to add the appropriate translation tables.
|
68
74
|
Globalize comes with a handy helper method to help you do this.
|
69
75
|
It's called `create_translation_table!`. Here's an example:
|
@@ -164,6 +170,11 @@ NOTE: Remember to add the new field to the model:
|
|
164
170
|
```ruby
|
165
171
|
translates :title, :author
|
166
172
|
```
|
173
|
+
## Gotchas
|
174
|
+
|
175
|
+
Because globalize uses the `:locale` key to specify the locale during
|
176
|
+
mass-assignment, you should avoid having a `locale` attribute on the parent
|
177
|
+
model.
|
167
178
|
|
168
179
|
## Versioning with Globalize
|
169
180
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2015-02-
|
17
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activerecord
|
@@ -153,7 +153,6 @@ files:
|
|
153
153
|
- LICENSE
|
154
154
|
- Rakefile
|
155
155
|
- globalize.gemspec
|
156
|
-
- init.rb
|
157
156
|
- lib/globalize.rb
|
158
157
|
- lib/globalize/active_record.rb
|
159
158
|
- lib/globalize/active_record/act_macro.rb
|
@@ -171,6 +170,7 @@ files:
|
|
171
170
|
- lib/i18n/missing_translations_raise_handler.rb
|
172
171
|
- lib/patches/active_record/persistence.rb
|
173
172
|
- lib/patches/active_record/query_method.rb
|
173
|
+
- lib/patches/active_record/serialization.rb
|
174
174
|
- lib/patches/active_record/uniqueness_validator.rb
|
175
175
|
- lib/patches/active_record/xml_attribute_serializer.rb
|
176
176
|
- readme.md
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'globalize'
|