globalize3 0.2.0.beta4 → 0.2.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -5
- data/Gemfile.lock +68 -81
- data/lib/globalize/active_record/instance_methods.rb +25 -12
- data/lib/globalize/active_record/migration.rb +36 -0
- data/lib/globalize3/version.rb +1 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,114 +9,101 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rack (~> 1.
|
23
|
-
rack-mount (~> 0.
|
24
|
-
rack-test (~> 0.
|
25
|
-
|
26
|
-
activemodel (3.
|
27
|
-
activesupport (= 3.
|
28
|
-
builder (~>
|
29
|
-
i18n (~> 0.
|
30
|
-
activerecord (3.
|
31
|
-
activemodel (= 3.
|
32
|
-
activesupport (= 3.
|
33
|
-
arel (~> 2.
|
34
|
-
tzinfo (~> 0.3.
|
35
|
-
activeresource (3.
|
36
|
-
activemodel (= 3.
|
37
|
-
activesupport (= 3.
|
38
|
-
activesupport (3.
|
39
|
-
|
40
|
-
arel (2.
|
41
|
-
builder (
|
42
|
-
columnize (0.3.4)
|
12
|
+
actionmailer (3.1.3)
|
13
|
+
actionpack (= 3.1.3)
|
14
|
+
mail (~> 2.3.0)
|
15
|
+
actionpack (3.1.3)
|
16
|
+
activemodel (= 3.1.3)
|
17
|
+
activesupport (= 3.1.3)
|
18
|
+
builder (~> 3.0.0)
|
19
|
+
erubis (~> 2.7.0)
|
20
|
+
i18n (~> 0.6)
|
21
|
+
rack (~> 1.3.5)
|
22
|
+
rack-cache (~> 1.1)
|
23
|
+
rack-mount (~> 0.8.2)
|
24
|
+
rack-test (~> 0.6.1)
|
25
|
+
sprockets (~> 2.0.3)
|
26
|
+
activemodel (3.1.3)
|
27
|
+
activesupport (= 3.1.3)
|
28
|
+
builder (~> 3.0.0)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
activerecord (3.1.3)
|
31
|
+
activemodel (= 3.1.3)
|
32
|
+
activesupport (= 3.1.3)
|
33
|
+
arel (~> 2.2.1)
|
34
|
+
tzinfo (~> 0.3.29)
|
35
|
+
activeresource (3.1.3)
|
36
|
+
activemodel (= 3.1.3)
|
37
|
+
activesupport (= 3.1.3)
|
38
|
+
activesupport (3.1.3)
|
39
|
+
multi_json (~> 1.0)
|
40
|
+
arel (2.2.1)
|
41
|
+
builder (3.0.0)
|
43
42
|
database_cleaner (0.5.2)
|
44
|
-
erubis (2.
|
45
|
-
|
46
|
-
i18n (0.
|
47
|
-
|
48
|
-
|
49
|
-
linecache19 (0.5.12)
|
50
|
-
ruby_core_source (>= 0.1.4)
|
51
|
-
mail (2.2.19)
|
52
|
-
activesupport (>= 2.3.6)
|
43
|
+
erubis (2.7.0)
|
44
|
+
hike (1.2.1)
|
45
|
+
i18n (0.6.0)
|
46
|
+
json (1.6.4)
|
47
|
+
mail (2.3.0)
|
53
48
|
i18n (>= 0.4.0)
|
54
49
|
mime-types (~> 1.16)
|
55
50
|
treetop (~> 1.4.8)
|
56
51
|
metaclass (0.0.1)
|
57
|
-
mime-types (1.
|
52
|
+
mime-types (1.17.2)
|
58
53
|
mocha (0.10.0)
|
59
54
|
metaclass (~> 0.0.1)
|
60
|
-
|
55
|
+
multi_json (1.0.4)
|
56
|
+
paper_trail (2.5.0)
|
61
57
|
rails (~> 3)
|
62
58
|
pathname_local (0.0.2)
|
63
|
-
polyglot (0.3.
|
64
|
-
rack (1.
|
65
|
-
rack-
|
59
|
+
polyglot (0.3.3)
|
60
|
+
rack (1.3.6)
|
61
|
+
rack-cache (1.1)
|
62
|
+
rack (>= 0.4)
|
63
|
+
rack-mount (0.8.3)
|
66
64
|
rack (>= 1.0.0)
|
67
|
-
rack-
|
65
|
+
rack-ssl (1.3.2)
|
66
|
+
rack
|
67
|
+
rack-test (0.6.1)
|
68
68
|
rack (>= 1.0)
|
69
|
-
rails (3.
|
70
|
-
actionmailer (= 3.
|
71
|
-
actionpack (= 3.
|
72
|
-
activerecord (= 3.
|
73
|
-
activeresource (= 3.
|
74
|
-
activesupport (= 3.
|
69
|
+
rails (3.1.3)
|
70
|
+
actionmailer (= 3.1.3)
|
71
|
+
actionpack (= 3.1.3)
|
72
|
+
activerecord (= 3.1.3)
|
73
|
+
activeresource (= 3.1.3)
|
74
|
+
activesupport (= 3.1.3)
|
75
75
|
bundler (~> 1.0)
|
76
|
-
railties (= 3.
|
77
|
-
railties (3.
|
78
|
-
actionpack (= 3.
|
79
|
-
activesupport (= 3.
|
76
|
+
railties (= 3.1.3)
|
77
|
+
railties (3.1.3)
|
78
|
+
actionpack (= 3.1.3)
|
79
|
+
activesupport (= 3.1.3)
|
80
|
+
rack-ssl (~> 1.3.2)
|
80
81
|
rake (>= 0.8.7)
|
81
82
|
rdoc (~> 3.4)
|
82
|
-
thor (~> 0.14.
|
83
|
-
rake (0.9.2)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
ruby-debug-base19 (0.11.25)
|
92
|
-
columnize (>= 0.3.1)
|
93
|
-
linecache19 (>= 0.5.11)
|
94
|
-
ruby_core_source (>= 0.1.4)
|
95
|
-
ruby-debug19 (0.11.6)
|
96
|
-
columnize (>= 0.3.1)
|
97
|
-
linecache19 (>= 0.5.11)
|
98
|
-
ruby-debug-base19 (>= 0.11.19)
|
99
|
-
ruby_core_source (0.1.5)
|
100
|
-
archive-tar-minitar (>= 0.5.2)
|
101
|
-
sqlite3 (1.3.4)
|
83
|
+
thor (~> 0.14.6)
|
84
|
+
rake (0.9.2.2)
|
85
|
+
rdoc (3.12)
|
86
|
+
json (~> 1.4)
|
87
|
+
sprockets (2.0.3)
|
88
|
+
hike (~> 1.2)
|
89
|
+
rack (~> 1.0)
|
90
|
+
tilt (~> 1.1, != 1.3.0)
|
91
|
+
sqlite3 (1.3.5)
|
102
92
|
test_declarative (0.0.5)
|
103
93
|
thor (0.14.6)
|
94
|
+
tilt (1.3.3)
|
104
95
|
treetop (1.4.10)
|
105
96
|
polyglot
|
106
97
|
polyglot (>= 0.3.1)
|
107
|
-
tzinfo (0.3.
|
98
|
+
tzinfo (0.3.31)
|
108
99
|
|
109
100
|
PLATFORMS
|
110
101
|
ruby
|
111
102
|
|
112
103
|
DEPENDENCIES
|
113
|
-
activemodel (= 3.0.10)
|
114
|
-
activerecord (= 3.0.10)
|
115
104
|
database_cleaner (= 0.5.2)
|
116
105
|
globalize3!
|
117
106
|
mocha
|
118
107
|
pathname_local
|
119
|
-
ruby-debug
|
120
|
-
ruby-debug19
|
121
108
|
sqlite3
|
122
109
|
test_declarative
|
@@ -11,16 +11,29 @@ module Globalize
|
|
11
11
|
super.merge(translated_attributes)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
def self.included(base)
|
15
|
+
# Maintain Rails 3.0.x compatibility while adding Rails 3.1.x compatibility
|
16
|
+
if base.method_defined?(:assign_attributes)
|
17
|
+
base.class_eval %{
|
18
|
+
def assign_attributes(attributes, options = {})
|
19
|
+
with_given_locale(attributes) { super }
|
20
|
+
end
|
21
|
+
}
|
22
|
+
else
|
23
|
+
base.class_eval %{
|
24
|
+
def attributes=(attributes, *args)
|
25
|
+
with_given_locale(attributes) { super }
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_attributes!(attributes, *args)
|
29
|
+
with_given_locale(attributes) { super }
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_attributes(attributes, *args)
|
33
|
+
with_given_locale(attributes) { super }
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
24
37
|
end
|
25
38
|
|
26
39
|
def write_attribute(name, value, options = {})
|
@@ -115,9 +128,9 @@ module Globalize
|
|
115
128
|
def translation_for(locale)
|
116
129
|
@translation_caches ||= {}
|
117
130
|
unless @translation_caches[locale]
|
118
|
-
#
|
119
|
-
# using either Model.includes(:translations) or Model.with_translations
|
131
|
+
# Fetch translations from database as those in the translation collection may be incomplete
|
120
132
|
_translation = translations.detect{|t| t.locale.to_s == locale.to_s}
|
133
|
+
_translation ||= translations.with_locale(locale).first
|
121
134
|
_translation ||= translations.build(:locale => locale)
|
122
135
|
@translation_caches[locale] = _translation
|
123
136
|
end
|
@@ -30,9 +30,16 @@ module Globalize
|
|
30
30
|
|
31
31
|
create_translation_table
|
32
32
|
move_data_to_translation_table if options[:migrate_data]
|
33
|
+
remove_source_columns if options[:remove_source_columns]
|
33
34
|
create_translations_index
|
34
35
|
end
|
35
36
|
|
37
|
+
def remove_source_columns
|
38
|
+
translated_attribute_names.each do |attribute|
|
39
|
+
connection.remove_column(table_name, attribute)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
36
43
|
def drop_translation_table!(options = {})
|
37
44
|
move_data_to_model_table if options[:migrate_data]
|
38
45
|
drop_translations_index
|
@@ -60,6 +67,11 @@ module Globalize
|
|
60
67
|
"#{table_name.sub(/^#{table_name_prefix}/, "").singularize}_id",
|
61
68
|
:name => translation_index_name
|
62
69
|
)
|
70
|
+
# index for select('DISTINCT locale') call in translation.rb
|
71
|
+
connection.add_index(
|
72
|
+
translations_table_name,
|
73
|
+
:locale
|
74
|
+
)
|
63
75
|
end
|
64
76
|
|
65
77
|
def drop_translation_table
|
@@ -71,6 +83,16 @@ module Globalize
|
|
71
83
|
end
|
72
84
|
|
73
85
|
def move_data_to_translation_table
|
86
|
+
# this refactored version might be a good idea,
|
87
|
+
# but only if made into a code that doesn't break tests
|
88
|
+
# model.find_each do |record|
|
89
|
+
# translation = record.translations.build(:locale => I18n.default_locale)
|
90
|
+
# translated_attribute_names.each do |attribute|
|
91
|
+
# translation[attribute] = record[attribute]
|
92
|
+
# end
|
93
|
+
# translation.save!
|
94
|
+
# end
|
95
|
+
|
74
96
|
# Find all of the existing untranslated attributes for this model.
|
75
97
|
all_model_fields = @model.all
|
76
98
|
model_attributes = all_model_fields.collect {|m| m.untranslated_attributes}
|
@@ -82,6 +104,8 @@ module Globalize
|
|
82
104
|
end
|
83
105
|
|
84
106
|
def move_data_to_model_table
|
107
|
+
add_missing_columns
|
108
|
+
|
85
109
|
# Find all of the translated attributes for all records in the model.
|
86
110
|
all_translated_attributes = @model.all.collect{|m| m.attributes}
|
87
111
|
all_translated_attributes.each do |translated_record|
|
@@ -119,6 +143,18 @@ module Globalize
|
|
119
143
|
index_name = "index_#{translations_table_name}_on_#{table_name.singularize}_id"
|
120
144
|
index_name.size < 50 ? index_name : "index_#{Digest::SHA1.hexdigest(index_name)}"
|
121
145
|
end
|
146
|
+
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def add_missing_columns
|
151
|
+
translated_attribute_names.map(&:to_s).each do |attribute|
|
152
|
+
unless model.column_names.include?(attribute)
|
153
|
+
connection.add_column(table_name, attribute, model::Translation.columns_hash[attribute].type)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
122
158
|
end
|
123
159
|
end
|
124
160
|
end
|
data/lib/globalize3/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -2195621950
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.2.0.
|
11
|
+
- 6
|
12
|
+
version: 0.2.0.beta6
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Sven Fuchs
|
@@ -22,7 +22,7 @@ autorequire:
|
|
22
22
|
bindir: bin
|
23
23
|
cert_chain: []
|
24
24
|
|
25
|
-
date:
|
25
|
+
date: 2012-01-11 00:00:00 Z
|
26
26
|
dependencies:
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|