globalize3 0.3.0 → 0.3.1
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 +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +32 -32
- data/lib/globalize.rb +8 -3
- data/lib/globalize/active_record/act_macro.rb +51 -36
- data/lib/globalize/active_record/adapter.rb +12 -3
- data/lib/globalize/active_record/class_methods.rb +18 -2
- data/lib/globalize/active_record/instance_methods.rb +40 -4
- data/lib/globalize/active_record/migration.rb +34 -15
- data/lib/globalize/active_record/translation.rb +1 -1
- data/lib/globalize/interpolation.rb +28 -0
- data/lib/globalize3/version.rb +1 -1
- data/lib/patches/active_record/relation.rb +15 -0
- metadata +46 -51
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3415e9c85d0bbf0c55f9006d9ad91f7522c2ccac
|
4
|
+
data.tar.gz: 8faa411a7dc53b2cda49fcc1cab52c336c22a7c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4d3c7485e0a2ddfa68dd471a40d5044b45c439f2f76b5a93186e5e28d7bae8993f8e20b882f659ca5a6baeb410580ce0bb0ca453159d58cba38dfa7cf94c6b8
|
7
|
+
data.tar.gz: 837b3b58a48ddf844d7796aabdac0b7436441d82b468ca1facebbbd6002d20435e672238e52de202016e843798ede5fbd189fc092ac87e3f60259320a0bb6838
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
globalize3 (0.3.
|
4
|
+
globalize3 (0.3.1)
|
5
5
|
activemodel (>= 3.0.0)
|
6
6
|
activerecord (>= 3.0.0)
|
7
7
|
paper_trail (~> 2)
|
8
8
|
|
9
9
|
GEM
|
10
|
-
remote:
|
10
|
+
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (3.2.
|
13
|
-
activemodel (= 3.2.
|
14
|
-
activesupport (= 3.2.
|
12
|
+
actionpack (3.2.15)
|
13
|
+
activemodel (= 3.2.15)
|
14
|
+
activesupport (= 3.2.15)
|
15
15
|
builder (~> 3.0.0)
|
16
16
|
erubis (~> 2.7.0)
|
17
17
|
journey (~> 1.0.4)
|
18
|
-
rack (~> 1.4.
|
18
|
+
rack (~> 1.4.5)
|
19
19
|
rack-cache (~> 1.2)
|
20
20
|
rack-test (~> 0.6.1)
|
21
21
|
sprockets (~> 2.2.1)
|
22
|
-
activemodel (3.2.
|
23
|
-
activesupport (= 3.2.
|
22
|
+
activemodel (3.2.15)
|
23
|
+
activesupport (= 3.2.15)
|
24
24
|
builder (~> 3.0.0)
|
25
|
-
activerecord (3.2.
|
26
|
-
activemodel (= 3.2.
|
27
|
-
activesupport (= 3.2.
|
25
|
+
activerecord (3.2.15)
|
26
|
+
activemodel (= 3.2.15)
|
27
|
+
activesupport (= 3.2.15)
|
28
28
|
arel (~> 3.0.2)
|
29
29
|
tzinfo (~> 0.3.29)
|
30
|
-
activesupport (3.2.
|
31
|
-
i18n (~> 0.6)
|
30
|
+
activesupport (3.2.15)
|
31
|
+
i18n (~> 0.6, >= 0.6.4)
|
32
32
|
multi_json (~> 1.0)
|
33
33
|
arel (3.0.2)
|
34
34
|
builder (3.0.4)
|
35
|
-
database_cleaner (0.
|
35
|
+
database_cleaner (0.6.7)
|
36
36
|
erubis (2.7.0)
|
37
|
-
hike (1.2.
|
38
|
-
i18n (0.6.
|
37
|
+
hike (1.2.3)
|
38
|
+
i18n (0.6.5)
|
39
39
|
journey (1.0.4)
|
40
|
-
json (1.
|
40
|
+
json (1.8.1)
|
41
41
|
metaclass (0.0.1)
|
42
|
-
mocha (0.
|
42
|
+
mocha (0.14.0)
|
43
43
|
metaclass (~> 0.0.1)
|
44
|
-
multi_json (1.
|
45
|
-
paper_trail (2.
|
44
|
+
multi_json (1.8.2)
|
45
|
+
paper_trail (2.7.2)
|
46
46
|
activerecord (~> 3.0)
|
47
47
|
railties (~> 3.0)
|
48
48
|
pathname_local (0.0.2)
|
49
|
-
rack (1.4.
|
49
|
+
rack (1.4.5)
|
50
50
|
rack-cache (1.2)
|
51
51
|
rack (>= 0.4)
|
52
|
-
rack-ssl (1.3.
|
52
|
+
rack-ssl (1.3.3)
|
53
53
|
rack
|
54
54
|
rack-test (0.6.2)
|
55
55
|
rack (>= 1.0)
|
56
|
-
railties (3.2.
|
57
|
-
actionpack (= 3.2.
|
58
|
-
activesupport (= 3.2.
|
56
|
+
railties (3.2.15)
|
57
|
+
actionpack (= 3.2.15)
|
58
|
+
activesupport (= 3.2.15)
|
59
59
|
rack-ssl (~> 1.3.2)
|
60
60
|
rake (>= 0.8.7)
|
61
61
|
rdoc (~> 3.4)
|
62
62
|
thor (>= 0.14.6, < 2.0)
|
63
|
-
rake (10.0
|
64
|
-
rdoc (3.12)
|
63
|
+
rake (10.1.0)
|
64
|
+
rdoc (3.12.2)
|
65
65
|
json (~> 1.4)
|
66
66
|
sprockets (2.2.2)
|
67
67
|
hike (~> 1.2)
|
68
68
|
multi_json (~> 1.0)
|
69
69
|
rack (~> 1.0)
|
70
70
|
tilt (~> 1.1, != 1.3.0)
|
71
|
-
sqlite3 (1.3.
|
71
|
+
sqlite3 (1.3.7)
|
72
72
|
test_declarative (0.0.5)
|
73
|
-
thor (0.
|
74
|
-
tilt (1.
|
75
|
-
tzinfo (0.3.
|
73
|
+
thor (0.18.1)
|
74
|
+
tilt (1.4.1)
|
75
|
+
tzinfo (0.3.38)
|
76
76
|
|
77
77
|
PLATFORMS
|
78
78
|
java
|
79
79
|
ruby
|
80
80
|
|
81
81
|
DEPENDENCIES
|
82
|
-
database_cleaner (
|
82
|
+
database_cleaner (~> 0.6.0)
|
83
83
|
globalize3!
|
84
84
|
mocha
|
85
85
|
pathname_local
|
data/lib/globalize.rb
CHANGED
@@ -2,10 +2,12 @@ require 'active_record'
|
|
2
2
|
require 'patches/active_record/xml_attribute_serializer'
|
3
3
|
require 'patches/active_record/query_method'
|
4
4
|
require 'patches/active_record/uniqueness_validator'
|
5
|
+
require 'patches/active_record/relation'
|
5
6
|
|
6
7
|
module Globalize
|
7
8
|
autoload :ActiveRecord, 'globalize/active_record'
|
8
9
|
autoload :Versioning, 'globalize/versioning'
|
10
|
+
autoload :Interpolation, 'globalize/interpolation'
|
9
11
|
|
10
12
|
class << self
|
11
13
|
def locale
|
@@ -18,9 +20,12 @@ module Globalize
|
|
18
20
|
|
19
21
|
def with_locale(locale, &block)
|
20
22
|
previous_locale = read_locale
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
begin
|
24
|
+
set_locale(locale)
|
25
|
+
result = yield(locale)
|
26
|
+
ensure
|
27
|
+
set_locale(previous_locale)
|
28
|
+
end
|
24
29
|
result
|
25
30
|
end
|
26
31
|
|
@@ -4,45 +4,19 @@ module Globalize
|
|
4
4
|
def translates(*attr_names)
|
5
5
|
|
6
6
|
options = attr_names.extract_options!
|
7
|
-
|
8
|
-
|
9
|
-
unless translates?
|
10
|
-
options[:table_name] ||= "#{table_name.singularize}_translations"
|
11
|
-
options[:foreign_key] ||= class_name.foreign_key
|
12
|
-
|
13
|
-
class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
|
14
|
-
self.translated_attribute_names = []
|
15
|
-
self.translation_options = options
|
16
|
-
self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
|
17
|
-
|
18
|
-
include InstanceMethods
|
19
|
-
extend ClassMethods, Migration
|
20
|
-
|
21
|
-
translation_class.table_name = options[:table_name] if translation_class.table_name.blank?
|
22
|
-
|
23
|
-
has_many :translations, :class_name => translation_class.name,
|
24
|
-
:foreign_key => options[:foreign_key],
|
25
|
-
:dependent => :destroy,
|
26
|
-
:extend => HasManyExtensions
|
27
|
-
|
28
|
-
after_create :save_translations!
|
29
|
-
after_update :save_translations!
|
30
|
-
|
31
|
-
if options[:versioning]
|
32
|
-
::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
|
7
|
+
setup_translates!(options) unless translates?
|
33
8
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
9
|
+
attr_names = attr_names.map(&:to_sym)
|
10
|
+
attr_names -= translated_attribute_names if defined?(translated_attribute_names)
|
37
11
|
|
12
|
+
if attr_names.present?
|
38
13
|
translation_class.instance_eval %{
|
39
|
-
attr_accessible :#{
|
14
|
+
attr_accessible :#{attr_names.join(', :')}
|
40
15
|
}
|
41
16
|
|
42
|
-
# detect and apply serialization
|
43
17
|
attr_names.each do |attr_name|
|
18
|
+
# Detect and apply serialization.
|
44
19
|
serializer = self.serialized_attributes[attr_name.to_s]
|
45
|
-
|
46
20
|
if serializer.present?
|
47
21
|
if defined?(::ActiveRecord::Coders::YAMLColumn) &&
|
48
22
|
serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
|
@@ -52,12 +26,15 @@ module Globalize
|
|
52
26
|
|
53
27
|
translation_class.send :serialize, attr_name, serializer
|
54
28
|
end
|
29
|
+
|
30
|
+
# Create accessors for the attribute.
|
31
|
+
translated_attr_accessor(attr_name)
|
32
|
+
translations_accessor(attr_name)
|
33
|
+
|
34
|
+
# Add attribute to the list.
|
35
|
+
self.translated_attribute_names << attr_name
|
55
36
|
end
|
56
37
|
end
|
57
|
-
|
58
|
-
new_attr_names = attr_names - translated_attribute_names
|
59
|
-
new_attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
|
60
|
-
self.translated_attribute_names += new_attr_names
|
61
38
|
end
|
62
39
|
|
63
40
|
def class_name
|
@@ -70,6 +47,44 @@ module Globalize
|
|
70
47
|
def translates?
|
71
48
|
included_modules.include?(InstanceMethods)
|
72
49
|
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
def setup_translates!(options)
|
53
|
+
options[:table_name] ||= "#{table_name.singularize}_translations"
|
54
|
+
options[:foreign_key] ||= class_name.foreign_key
|
55
|
+
|
56
|
+
class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
|
57
|
+
self.translated_attribute_names = []
|
58
|
+
self.translation_options = options
|
59
|
+
self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
|
60
|
+
|
61
|
+
include InstanceMethods
|
62
|
+
extend ClassMethods, Migration
|
63
|
+
|
64
|
+
translation_class.table_name = options[:table_name]
|
65
|
+
|
66
|
+
has_many :translations, :class_name => translation_class.name,
|
67
|
+
:foreign_key => options[:foreign_key],
|
68
|
+
:dependent => :destroy,
|
69
|
+
:extend => HasManyExtensions,
|
70
|
+
:autosave => false
|
71
|
+
|
72
|
+
after_create :save_translations!
|
73
|
+
after_update :save_translations!
|
74
|
+
|
75
|
+
if options[:versioning]
|
76
|
+
if options[:versioning].is_a?(Hash)
|
77
|
+
translation_class.versioned options[:versioning]
|
78
|
+
else
|
79
|
+
::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
|
80
|
+
|
81
|
+
translation_class.has_paper_trail
|
82
|
+
delegate :version, :versions, :to => :translation
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
translation_class.instance_eval %{ attr_accessible :locale }
|
87
|
+
end
|
73
88
|
end
|
74
89
|
|
75
90
|
module HasManyExtensions
|
@@ -19,6 +19,10 @@ module Globalize
|
|
19
19
|
return nil
|
20
20
|
end
|
21
21
|
|
22
|
+
def stash_contains?(locale, name)
|
23
|
+
stash.contains?(locale, name)
|
24
|
+
end
|
25
|
+
|
22
26
|
def fetch(locale, name)
|
23
27
|
record.globalize_fallbacks(locale).each do |fallback|
|
24
28
|
value = stash.contains?(fallback, name) ? fetch_stash(fallback, name) : fetch_attribute(fallback, name)
|
@@ -37,16 +41,21 @@ module Globalize
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def save_translations!
|
44
|
+
existing_translations_by_locale = {}
|
45
|
+
record.translations.each do |t|
|
46
|
+
existing_translations_by_locale[t.locale.to_s] = t
|
47
|
+
end
|
48
|
+
|
40
49
|
stash.each do |locale, attrs|
|
41
50
|
if attrs.any?
|
42
|
-
|
51
|
+
locale_str = locale.to_s
|
52
|
+
translation = existing_translations_by_locale[locale_str] ||
|
53
|
+
record.translations.find_or_initialize_by_locale(locale_str)
|
43
54
|
attrs.each { |name, value| translation[name] = value }
|
44
55
|
translation.save!
|
45
56
|
end
|
46
57
|
end
|
47
58
|
|
48
|
-
record.translations.each(&:reload)
|
49
|
-
record.translations.reset
|
50
59
|
reset
|
51
60
|
end
|
52
61
|
|
@@ -45,7 +45,7 @@ module Globalize
|
|
45
45
|
klass = self.const_set(:Translation, Class.new(Globalize::ActiveRecord::Translation))
|
46
46
|
end
|
47
47
|
|
48
|
-
klass.belongs_to
|
48
|
+
klass.belongs_to :globalized_model, :class_name => self.name, :foreign_key => translation_options[:foreign_key]
|
49
49
|
klass
|
50
50
|
end
|
51
51
|
end
|
@@ -145,11 +145,27 @@ module Globalize
|
|
145
145
|
write_attribute(name, value)
|
146
146
|
end
|
147
147
|
define_method(name) do |*args|
|
148
|
-
|
148
|
+
Globalize::Interpolation.interpolate(name, self, args)
|
149
149
|
end
|
150
150
|
alias_method :"#{name}_before_type_cast", name
|
151
151
|
end
|
152
152
|
|
153
|
+
def translations_accessor(name)
|
154
|
+
define_method(:"#{name}_translations") do
|
155
|
+
result = translations.each_with_object(HashWithIndifferentAccess.new) do |translation, result|
|
156
|
+
result[translation.locale] = translation.send(name)
|
157
|
+
end
|
158
|
+
globalize.stash.keys.each_with_object(result) do |locale, result|
|
159
|
+
result[locale] = globalize.fetch_stash(locale, name) if globalize.stash_contains?(locale, name)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
define_method(:"#{name}_translations=") do |value|
|
163
|
+
value.each do |(locale, value)|
|
164
|
+
write_attribute name, value, :locale => locale
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
153
169
|
end
|
154
170
|
|
155
171
|
end
|
@@ -44,8 +44,21 @@ module Globalize
|
|
44
44
|
options = {:locale => options}
|
45
45
|
end
|
46
46
|
options = {:locale => Globalize.locale}.merge(options)
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
# Dirty tracking, paraphrased from
|
49
|
+
# ActiveRecord::AttributeMethods::Dirty#write_attribute.
|
50
|
+
name_str = name.to_s
|
51
|
+
if attribute_changed?(name_str)
|
52
|
+
# If there's already a change, delete it if this undoes the change.
|
53
|
+
old = changed_attributes[name_str]
|
54
|
+
changed_attributes.delete(name_str) if value == old
|
55
|
+
else
|
56
|
+
# If there's not a change yet, record it.
|
57
|
+
old = globalize.fetch(options[:locale], name)
|
58
|
+
old = old.clone if old.duplicable?
|
59
|
+
changed_attributes[name_str] = old if value != old
|
60
|
+
end
|
61
|
+
|
49
62
|
globalize.write(options[:locale], name, value)
|
50
63
|
else
|
51
64
|
super(name, value)
|
@@ -63,7 +76,7 @@ module Globalize
|
|
63
76
|
if self.class.translated?(name) and options[:translated]
|
64
77
|
if (value = globalize.fetch(options[:locale] || Globalize.locale, name))
|
65
78
|
value
|
66
|
-
|
79
|
+
else
|
67
80
|
super(name)
|
68
81
|
end
|
69
82
|
else
|
@@ -105,6 +118,7 @@ module Globalize
|
|
105
118
|
end
|
106
119
|
translation.save
|
107
120
|
end
|
121
|
+
globalize.reset
|
108
122
|
end
|
109
123
|
|
110
124
|
def reload(options = nil)
|
@@ -154,6 +168,24 @@ module Globalize
|
|
154
168
|
translation_caches[::Globalize.locale] = translation.previous_version
|
155
169
|
end
|
156
170
|
|
171
|
+
def column_for_attribute name
|
172
|
+
translated_attribute_names.include?(name) ? globalize.send(:column_for_attribute, name) : super
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def update(*)
|
178
|
+
I18n.with_locale(read_attribute(:locale) || I18n.default_locale) do
|
179
|
+
super
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def create(*)
|
184
|
+
I18n.with_locale(read_attribute(:locale) || I18n.default_locale) do
|
185
|
+
super
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
157
189
|
protected
|
158
190
|
|
159
191
|
def each_locale_and_translated_attribute
|
@@ -177,7 +209,11 @@ module Globalize
|
|
177
209
|
|
178
210
|
def with_given_locale(attributes, &block)
|
179
211
|
attributes.symbolize_keys! if attributes.respond_to?(:symbolize_keys!)
|
180
|
-
|
212
|
+
|
213
|
+
locale = respond_to?(:locale=) ? attributes.try(:[], :locale) :
|
214
|
+
attributes.try(:delete, :locale)
|
215
|
+
|
216
|
+
if locale
|
181
217
|
Globalize.with_locale(locale, &block)
|
182
218
|
else
|
183
219
|
yield
|
@@ -9,7 +9,7 @@ module Globalize
|
|
9
9
|
@globalize_migrator ||= Migrator.new(self)
|
10
10
|
end
|
11
11
|
|
12
|
-
delegate :create_translation_table!, :drop_translation_table!,
|
12
|
+
delegate :create_translation_table!, :add_translation_fields!, :drop_translation_table!,
|
13
13
|
:translation_index_name, :translation_locale_index_name,
|
14
14
|
:to => :globalize_migrator
|
15
15
|
|
@@ -26,20 +26,29 @@ module Globalize
|
|
26
26
|
|
27
27
|
def create_translation_table!(fields = {}, options = {})
|
28
28
|
@fields = fields
|
29
|
-
|
29
|
+
# If we have fields we only want to create the translation table with those fields
|
30
|
+
complete_translated_fields if fields.blank?
|
30
31
|
validate_translated_fields
|
31
32
|
|
32
33
|
create_translation_table
|
34
|
+
add_translation_fields!(fields, options)
|
35
|
+
create_translations_index
|
36
|
+
clear_schema_cache!
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_translation_fields!(fields, options = {})
|
40
|
+
@fields = fields
|
41
|
+
validate_translated_fields
|
42
|
+
|
43
|
+
add_translation_fields
|
44
|
+
clear_schema_cache!
|
33
45
|
move_data_to_translation_table if options[:migrate_data]
|
34
46
|
remove_source_columns if options[:remove_source_columns]
|
35
|
-
create_translations_index
|
36
47
|
clear_schema_cache!
|
37
48
|
end
|
38
49
|
|
39
50
|
def remove_source_columns
|
40
|
-
|
41
|
-
connection.remove_column(table_name, attribute)
|
42
|
-
end
|
51
|
+
connection.remove_columns(table_name, *fields.keys)
|
43
52
|
end
|
44
53
|
|
45
54
|
def drop_translation_table!(options = {})
|
@@ -49,6 +58,8 @@ module Globalize
|
|
49
58
|
clear_schema_cache!
|
50
59
|
end
|
51
60
|
|
61
|
+
# This adds all the current translated attributes of the model
|
62
|
+
# It's a problem because in early migrations would add all the translated attributes
|
52
63
|
def complete_translated_fields
|
53
64
|
translated_attribute_names.each do |name|
|
54
65
|
fields[name] = column_type(name) unless fields[name]
|
@@ -57,8 +68,14 @@ module Globalize
|
|
57
68
|
|
58
69
|
def create_translation_table
|
59
70
|
connection.create_table(translations_table_name) do |t|
|
60
|
-
t.references table_name.sub(/^#{table_name_prefix}/, '').singularize
|
61
|
-
t.string :locale
|
71
|
+
t.references table_name.sub(/^#{table_name_prefix}/, '').singularize, :null => false
|
72
|
+
t.string :locale, :null => false
|
73
|
+
t.timestamps
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_translation_fields
|
78
|
+
connection.change_table(translations_table_name) do |t|
|
62
79
|
fields.each do |name, options|
|
63
80
|
if options.is_a? Hash
|
64
81
|
t.column name, options.delete(:type), options
|
@@ -66,7 +83,6 @@ module Globalize
|
|
66
83
|
t.column name, options
|
67
84
|
end
|
68
85
|
end
|
69
|
-
t.timestamps
|
70
86
|
end
|
71
87
|
end
|
72
88
|
|
@@ -94,10 +110,9 @@ module Globalize
|
|
94
110
|
|
95
111
|
def move_data_to_translation_table
|
96
112
|
model.find_each do |record|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
translation[attribute] = untranslated_attributes[attribute.to_s]
|
113
|
+
translation = record.translation_for(I18n.default_locale) || record.translations.build(:locale => I18n.default_locale)
|
114
|
+
fields.each do |attribute_name, attribute_type|
|
115
|
+
translation[attribute_name] = record.read_attribute(attribute_name, {:translated => false})
|
101
116
|
end
|
102
117
|
translation.save!
|
103
118
|
end
|
@@ -144,16 +159,20 @@ module Globalize
|
|
144
159
|
|
145
160
|
def translation_index_name
|
146
161
|
index_name = "index_#{translations_table_name}_on_#{table_name.singularize}_id"
|
147
|
-
index_name.size < connection.index_name_length ? index_name :
|
162
|
+
index_name.size < connection.index_name_length ? index_name :
|
163
|
+
"index_#{Digest::SHA1.hexdigest(index_name)}"[0, connection.index_name_length]
|
148
164
|
end
|
149
165
|
|
150
166
|
def translation_locale_index_name
|
151
167
|
index_name = "index_#{translations_table_name}_on_locale"
|
152
|
-
index_name.size < connection.index_name_length ? index_name :
|
168
|
+
index_name.size < connection.index_name_length ? index_name :
|
169
|
+
"index_#{Digest::SHA1.hexdigest(index_name)}"[0, connection.index_name_length]
|
153
170
|
end
|
154
171
|
|
155
172
|
def clear_schema_cache!
|
156
173
|
connection.schema_cache.clear! if connection.respond_to? :schema_cache
|
174
|
+
model::Translation.reset_column_information
|
175
|
+
model.reset_column_information
|
157
176
|
end
|
158
177
|
|
159
178
|
private
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Globalize
|
2
|
+
module Interpolation
|
3
|
+
def interpolate(name, model, args)
|
4
|
+
translation = model.read_attribute(name, {:locale => locale_from(args)})
|
5
|
+
try_interpolation translation, interpolation_args_from(args)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def interpolation_args_from(args)
|
11
|
+
args.detect {|a| a.is_a? Hash }
|
12
|
+
end
|
13
|
+
|
14
|
+
def locale_from(args)
|
15
|
+
args.detect {|a| !a.is_a? Hash }
|
16
|
+
end
|
17
|
+
|
18
|
+
def try_interpolation(translation,args)
|
19
|
+
if args
|
20
|
+
I18n.interpolate(translation,args)
|
21
|
+
else
|
22
|
+
translation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
extend self
|
27
|
+
end
|
28
|
+
end
|
data/lib/globalize3/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Relation
|
3
|
+
if ::ActiveRecord::VERSION::STRING >= "3.2.1"
|
4
|
+
def where_values_hash
|
5
|
+
_translations_table_name = klass.respond_to?(:translations_table_name) ? klass.translations_table_name : nil
|
6
|
+
|
7
|
+
equalities = with_default_scope.where_values.grep(Arel::Nodes::Equality).find_all { |node|
|
8
|
+
[table_name, _translations_table_name].compact.include? node.left.relation.name
|
9
|
+
}
|
10
|
+
|
11
|
+
Hash[equalities.map { |where| [where.left.name, where.right] }].with_indifferent_access
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sven Fuchs
|
@@ -11,139 +10,124 @@ authors:
|
|
11
10
|
- John-Paul Bader
|
12
11
|
- Tomasz Stachewicz
|
13
12
|
- Philip Arndt
|
13
|
+
- Chris Salzberg
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date:
|
17
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activerecord
|
21
|
-
prerelease: false
|
22
21
|
requirement: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- -
|
23
|
+
- - '>='
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: 3.0.0
|
27
|
-
none: false
|
28
26
|
type: :runtime
|
27
|
+
prerelease: false
|
29
28
|
version_requirements: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
|
-
- -
|
30
|
+
- - '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: 3.0.0
|
34
|
-
none: false
|
35
33
|
- !ruby/object:Gem::Dependency
|
36
34
|
name: activemodel
|
37
|
-
prerelease: false
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
36
|
requirements:
|
40
|
-
- -
|
37
|
+
- - '>='
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: 3.0.0
|
43
|
-
none: false
|
44
40
|
type: :runtime
|
41
|
+
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
46
43
|
requirements:
|
47
|
-
- -
|
44
|
+
- - '>='
|
48
45
|
- !ruby/object:Gem::Version
|
49
46
|
version: 3.0.0
|
50
|
-
none: false
|
51
47
|
- !ruby/object:Gem::Dependency
|
52
48
|
name: paper_trail
|
53
|
-
prerelease: false
|
54
49
|
requirement: !ruby/object:Gem::Requirement
|
55
50
|
requirements:
|
56
51
|
- - ~>
|
57
52
|
- !ruby/object:Gem::Version
|
58
53
|
version: '2'
|
59
|
-
none: false
|
60
54
|
type: :runtime
|
55
|
+
prerelease: false
|
61
56
|
version_requirements: !ruby/object:Gem::Requirement
|
62
57
|
requirements:
|
63
58
|
- - ~>
|
64
59
|
- !ruby/object:Gem::Version
|
65
60
|
version: '2'
|
66
|
-
none: false
|
67
61
|
- !ruby/object:Gem::Dependency
|
68
62
|
name: database_cleaner
|
69
|
-
prerelease: false
|
70
63
|
requirement: !ruby/object:Gem::Requirement
|
71
64
|
requirements:
|
72
|
-
- -
|
65
|
+
- - ~>
|
73
66
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
75
|
-
none: false
|
67
|
+
version: 0.6.0
|
76
68
|
type: :development
|
69
|
+
prerelease: false
|
77
70
|
version_requirements: !ruby/object:Gem::Requirement
|
78
71
|
requirements:
|
79
|
-
- -
|
72
|
+
- - ~>
|
80
73
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.
|
82
|
-
none: false
|
74
|
+
version: 0.6.0
|
83
75
|
- !ruby/object:Gem::Dependency
|
84
76
|
name: mocha
|
85
|
-
prerelease: false
|
86
77
|
requirement: !ruby/object:Gem::Requirement
|
87
78
|
requirements:
|
88
|
-
- -
|
79
|
+
- - '>='
|
89
80
|
- !ruby/object:Gem::Version
|
90
81
|
version: '0'
|
91
|
-
none: false
|
92
82
|
type: :development
|
83
|
+
prerelease: false
|
93
84
|
version_requirements: !ruby/object:Gem::Requirement
|
94
85
|
requirements:
|
95
|
-
- -
|
86
|
+
- - '>='
|
96
87
|
- !ruby/object:Gem::Version
|
97
88
|
version: '0'
|
98
|
-
none: false
|
99
89
|
- !ruby/object:Gem::Dependency
|
100
90
|
name: pathname_local
|
101
|
-
prerelease: false
|
102
91
|
requirement: !ruby/object:Gem::Requirement
|
103
92
|
requirements:
|
104
|
-
- -
|
93
|
+
- - '>='
|
105
94
|
- !ruby/object:Gem::Version
|
106
95
|
version: '0'
|
107
|
-
none: false
|
108
96
|
type: :development
|
97
|
+
prerelease: false
|
109
98
|
version_requirements: !ruby/object:Gem::Requirement
|
110
99
|
requirements:
|
111
|
-
- -
|
100
|
+
- - '>='
|
112
101
|
- !ruby/object:Gem::Version
|
113
102
|
version: '0'
|
114
|
-
none: false
|
115
103
|
- !ruby/object:Gem::Dependency
|
116
104
|
name: test_declarative
|
117
|
-
prerelease: false
|
118
105
|
requirement: !ruby/object:Gem::Requirement
|
119
106
|
requirements:
|
120
|
-
- -
|
107
|
+
- - '>='
|
121
108
|
- !ruby/object:Gem::Version
|
122
109
|
version: '0'
|
123
|
-
none: false
|
124
110
|
type: :development
|
111
|
+
prerelease: false
|
125
112
|
version_requirements: !ruby/object:Gem::Requirement
|
126
113
|
requirements:
|
127
|
-
- -
|
114
|
+
- - '>='
|
128
115
|
- !ruby/object:Gem::Version
|
129
116
|
version: '0'
|
130
|
-
none: false
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
118
|
name: sqlite3
|
133
|
-
prerelease: false
|
134
119
|
requirement: !ruby/object:Gem::Requirement
|
135
120
|
requirements:
|
136
|
-
- -
|
121
|
+
- - '>='
|
137
122
|
- !ruby/object:Gem::Version
|
138
123
|
version: '0'
|
139
|
-
none: false
|
140
124
|
type: :development
|
125
|
+
prerelease: false
|
141
126
|
version_requirements: !ruby/object:Gem::Requirement
|
142
127
|
requirements:
|
143
|
-
- -
|
128
|
+
- - '>='
|
144
129
|
- !ruby/object:Gem::Version
|
145
130
|
version: '0'
|
146
|
-
none: false
|
147
131
|
description: Rails I18n de-facto standard library for ActiveRecord 3 model/data translation.
|
148
132
|
email: nobody@globalize-rails.org
|
149
133
|
executables: []
|
@@ -159,6 +143,7 @@ files:
|
|
159
143
|
- lib/globalize/active_record/migration.rb
|
160
144
|
- lib/globalize/active_record/translation.rb
|
161
145
|
- lib/globalize/active_record.rb
|
146
|
+
- lib/globalize/interpolation.rb
|
162
147
|
- lib/globalize/versioning/paper_trail.rb
|
163
148
|
- lib/globalize/versioning.rb
|
164
149
|
- lib/globalize.rb
|
@@ -167,6 +152,7 @@ files:
|
|
167
152
|
- lib/i18n/missing_translations_log_handler.rb
|
168
153
|
- lib/i18n/missing_translations_raise_handler.rb
|
169
154
|
- lib/patches/active_record/query_method.rb
|
155
|
+
- lib/patches/active_record/relation.rb
|
170
156
|
- lib/patches/active_record/uniqueness_validator.rb
|
171
157
|
- lib/patches/active_record/xml_attribute_serializer.rb
|
172
158
|
- Gemfile
|
@@ -175,27 +161,36 @@ files:
|
|
175
161
|
- Rakefile
|
176
162
|
homepage: http://github.com/svenfuchs/globalize3
|
177
163
|
licenses: []
|
178
|
-
|
164
|
+
metadata: {}
|
165
|
+
post_install_message: |2+
|
166
|
+
|
167
|
+
HEADS UP! Globalize3 has been renamed "Globalize" and now supports both
|
168
|
+
ActiveRecord 3.x and ActiveRecord 4. To use the new gem with ActiveRecord
|
169
|
+
3.x, replace "gem 'globalize3'" with "gem 'globalize', '~> 3.0.0'" in your
|
170
|
+
Gemfile.
|
171
|
+
|
172
|
+
All future updates to the ActiveRecord 3.x version of Globalize will happen
|
173
|
+
in versions 3.x of the new gem (globalize). globalize3 is deprecated and will
|
174
|
+
no longer be updated.
|
175
|
+
|
179
176
|
rdoc_options: []
|
180
177
|
require_paths:
|
181
178
|
- lib
|
182
179
|
required_ruby_version: !ruby/object:Gem::Requirement
|
183
180
|
requirements:
|
184
|
-
- -
|
181
|
+
- - '>='
|
185
182
|
- !ruby/object:Gem::Version
|
186
183
|
version: '0'
|
187
|
-
none: false
|
188
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
185
|
requirements:
|
190
|
-
- -
|
186
|
+
- - '>='
|
191
187
|
- !ruby/object:Gem::Version
|
192
188
|
version: '0'
|
193
|
-
none: false
|
194
189
|
requirements: []
|
195
|
-
rubyforge_project:
|
196
|
-
rubygems_version: 1.
|
190
|
+
rubyforge_project: '[none]'
|
191
|
+
rubygems_version: 2.1.0
|
197
192
|
signing_key:
|
198
|
-
specification_version:
|
193
|
+
specification_version: 4
|
199
194
|
summary: Rails I18n de-facto standard library for ActiveRecord 3 model/data translation
|
200
195
|
test_files: []
|
201
196
|
has_rdoc:
|