globalize3 0.2.0.beta1 → 0.2.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
globalize3 (0.2.0.
|
4
|
+
globalize3 (0.2.0.beta2)
|
5
5
|
activemodel (>= 3.0.0)
|
6
6
|
activerecord (>= 3.0.0)
|
7
7
|
paper_trail (~> 2)
|
@@ -10,12 +10,12 @@ GEM
|
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
12
|
abstract (1.0.0)
|
13
|
-
actionmailer (3.0.
|
14
|
-
actionpack (= 3.0.
|
15
|
-
mail (~> 2.2.
|
16
|
-
actionpack (3.0.
|
17
|
-
activemodel (= 3.0.
|
18
|
-
activesupport (= 3.0.
|
13
|
+
actionmailer (3.0.9)
|
14
|
+
actionpack (= 3.0.9)
|
15
|
+
mail (~> 2.2.19)
|
16
|
+
actionpack (3.0.9)
|
17
|
+
activemodel (= 3.0.9)
|
18
|
+
activesupport (= 3.0.9)
|
19
19
|
builder (~> 2.1.2)
|
20
20
|
erubis (~> 2.6.6)
|
21
21
|
i18n (~> 0.5.0)
|
@@ -23,19 +23,19 @@ GEM
|
|
23
23
|
rack-mount (~> 0.6.14)
|
24
24
|
rack-test (~> 0.5.7)
|
25
25
|
tzinfo (~> 0.3.23)
|
26
|
-
activemodel (3.0.
|
27
|
-
activesupport (= 3.0.
|
26
|
+
activemodel (3.0.9)
|
27
|
+
activesupport (= 3.0.9)
|
28
28
|
builder (~> 2.1.2)
|
29
29
|
i18n (~> 0.5.0)
|
30
|
-
activerecord (3.0.
|
31
|
-
activemodel (= 3.0.
|
32
|
-
activesupport (= 3.0.
|
33
|
-
arel (~> 2.0.
|
30
|
+
activerecord (3.0.9)
|
31
|
+
activemodel (= 3.0.9)
|
32
|
+
activesupport (= 3.0.9)
|
33
|
+
arel (~> 2.0.10)
|
34
34
|
tzinfo (~> 0.3.23)
|
35
|
-
activeresource (3.0.
|
36
|
-
activemodel (= 3.0.
|
37
|
-
activesupport (= 3.0.
|
38
|
-
activesupport (3.0.
|
35
|
+
activeresource (3.0.9)
|
36
|
+
activemodel (= 3.0.9)
|
37
|
+
activesupport (= 3.0.9)
|
38
|
+
activesupport (3.0.9)
|
39
39
|
archive-tar-minitar (0.5.2)
|
40
40
|
arel (2.0.10)
|
41
41
|
builder (2.1.2)
|
@@ -54,29 +54,31 @@ GEM
|
|
54
54
|
mime-types (1.16)
|
55
55
|
mocha (0.9.10)
|
56
56
|
rake
|
57
|
-
paper_trail (2.2.
|
57
|
+
paper_trail (2.2.9)
|
58
58
|
rails (~> 3)
|
59
59
|
pathname_local (0.0.2)
|
60
|
-
polyglot (0.3.
|
60
|
+
polyglot (0.3.2)
|
61
61
|
rack (1.2.3)
|
62
62
|
rack-mount (0.6.14)
|
63
63
|
rack (>= 1.0.0)
|
64
64
|
rack-test (0.5.7)
|
65
65
|
rack (>= 1.0)
|
66
|
-
rails (3.0.
|
67
|
-
actionmailer (= 3.0.
|
68
|
-
actionpack (= 3.0.
|
69
|
-
activerecord (= 3.0.
|
70
|
-
activeresource (= 3.0.
|
71
|
-
activesupport (= 3.0.
|
66
|
+
rails (3.0.9)
|
67
|
+
actionmailer (= 3.0.9)
|
68
|
+
actionpack (= 3.0.9)
|
69
|
+
activerecord (= 3.0.9)
|
70
|
+
activeresource (= 3.0.9)
|
71
|
+
activesupport (= 3.0.9)
|
72
72
|
bundler (~> 1.0)
|
73
|
-
railties (= 3.0.
|
74
|
-
railties (3.0.
|
75
|
-
actionpack (= 3.0.
|
76
|
-
activesupport (= 3.0.
|
73
|
+
railties (= 3.0.9)
|
74
|
+
railties (3.0.9)
|
75
|
+
actionpack (= 3.0.9)
|
76
|
+
activesupport (= 3.0.9)
|
77
77
|
rake (>= 0.8.7)
|
78
|
+
rdoc (~> 3.4)
|
78
79
|
thor (~> 0.14.4)
|
79
80
|
rake (0.8.7)
|
81
|
+
rdoc (3.9.2)
|
80
82
|
ruby-debug-base19 (0.11.25)
|
81
83
|
columnize (>= 0.3.1)
|
82
84
|
linecache19 (>= 0.5.11)
|
@@ -90,9 +92,10 @@ GEM
|
|
90
92
|
sqlite3-ruby (1.3.2)
|
91
93
|
test_declarative (0.0.5)
|
92
94
|
thor (0.14.6)
|
93
|
-
treetop (1.4.
|
95
|
+
treetop (1.4.10)
|
96
|
+
polyglot
|
94
97
|
polyglot (>= 0.3.1)
|
95
|
-
tzinfo (0.3.
|
98
|
+
tzinfo (0.3.29)
|
96
99
|
|
97
100
|
PLATFORMS
|
98
101
|
ruby
|
data/README.textile
CHANGED
@@ -39,6 +39,10 @@ post.title # => גלובאלייז2 שולט!
|
|
39
39
|
|
40
40
|
In order to make this work, you'll need to add the appropriate translation tables. Globalize3 comes with a handy helper method to help you do this. It's called @create_translation_table!@. Here's an example:
|
41
41
|
|
42
|
+
<em>Note that if you're using rails ~> 3.1.0.rc migrations has only the <tt>change</tt> instance method</em>
|
43
|
+
|
44
|
+
h3. Rails 3.0
|
45
|
+
|
42
46
|
<pre><code>
|
43
47
|
class CreatePosts < ActiveRecord::Migration
|
44
48
|
def self.up
|
@@ -54,6 +58,25 @@ class CreatePosts < ActiveRecord::Migration
|
|
54
58
|
end
|
55
59
|
</code></pre>
|
56
60
|
|
61
|
+
h3. Rails ~> 3.1.0.rc
|
62
|
+
|
63
|
+
<em>Do not use the change method</em>
|
64
|
+
|
65
|
+
<pre><code>
|
66
|
+
class CreatePosts < ActiveRecord::Migration
|
67
|
+
def 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 down
|
74
|
+
drop_table :posts
|
75
|
+
Post.drop_translation_table!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
</code></pre>
|
79
|
+
|
57
80
|
Note that the ActiveRecord model @Post@ must already exist and have a @translates@ directive listing the translated fields.
|
58
81
|
|
59
82
|
h2. Migrating existing data to and from the translated version
|
@@ -95,6 +118,64 @@ Please also note that @update_attribute@ currently hides itself from dirty track
|
|
95
118
|
|
96
119
|
Also, please see the tests in test/globalize3/versioning_test.rb for some current gotchas.
|
97
120
|
|
121
|
+
h2. I18n fallbacks for empty translations
|
122
|
+
|
123
|
+
It is possible to enable fallbacks for empty translations. It will depend on the configuration setting you have set for I18n translations in your Rails config.
|
124
|
+
|
125
|
+
You can enable them by adding the next line to @config/application.rb@ (or only @config/environments/production.rb@ if you only want them in production)
|
126
|
+
|
127
|
+
<pre><code>config.i18n.fallbacks = true</code></pre>
|
128
|
+
|
129
|
+
By default, globalize3 will only use fallbacks when your translation model does not exist or the translation value for the item you've requested is @nil@. However it is possible to also use fallbacks for @blank@ translations by adding @:fallbacks_for_empty_translations => true@ to the @translates@ method.
|
130
|
+
|
131
|
+
<pre><code>
|
132
|
+
class Post < ActiveRecord::Base
|
133
|
+
translates :title, :name
|
134
|
+
end
|
135
|
+
|
136
|
+
puts post.translations.inspect
|
137
|
+
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize3 rocks!", name: "Globalize3">, #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
|
138
|
+
|
139
|
+
I18n.locale = :en
|
140
|
+
post.title # => 'Globalize3 rocks!'
|
141
|
+
post.name # => 'Globalize3'
|
142
|
+
|
143
|
+
I18n.locale = :nl
|
144
|
+
post.title # => ''
|
145
|
+
post.name # => 'Globalize3'
|
146
|
+
</code></pre>
|
147
|
+
<pre><code>
|
148
|
+
class Post < ActiveRecord::Base
|
149
|
+
translates :title, :name, :fallbacks_for_empty_translations => true
|
150
|
+
end
|
151
|
+
|
152
|
+
puts post.translations.inspect
|
153
|
+
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize3 rocks!", name: "Globalize3">, #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
|
154
|
+
|
155
|
+
I18n.locale = :en
|
156
|
+
post.title # => 'Globalize3 rocks!'
|
157
|
+
post.name # => 'Globalize3'
|
158
|
+
|
159
|
+
I18n.locale = :nl
|
160
|
+
post.title # => 'Globalize3 rocks!'
|
161
|
+
post.name # => 'Globalize3'
|
162
|
+
</code></pre>
|
163
|
+
|
164
|
+
|
165
|
+
h2. Scoping objects by those with translations
|
166
|
+
|
167
|
+
To only return objects that have a translation for the given locale we can use the `with_translations` scope. This will only return records that have a translations for the passed in locale.
|
168
|
+
|
169
|
+
<pre><code>
|
170
|
+
|
171
|
+
Post.with_translations('en') # => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize3 rocks!", name: "Globalize3">, #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
|
172
|
+
|
173
|
+
Post.with_translations(I18n.locale) # => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize3 rocks!", name: "Globalize3">, #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
|
174
|
+
|
175
|
+
Post.with_translations('de') # => []
|
176
|
+
|
177
|
+
</code></pre>
|
178
|
+
|
98
179
|
h2. Changes since Globalize2
|
99
180
|
|
100
181
|
* `translation_table_name` was renamed to `translations_table_name`
|
@@ -7,9 +7,10 @@ module Globalize
|
|
7
7
|
options = attr_names.extract_options!
|
8
8
|
options[:table_name] ||= "#{table_name.singularize}_translations"
|
9
9
|
|
10
|
-
class_attribute :translated_attribute_names, :translation_options
|
10
|
+
class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
|
11
11
|
self.translated_attribute_names = attr_names.map(&:to_sym)
|
12
12
|
self.translation_options = options
|
13
|
+
self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
|
13
14
|
|
14
15
|
include InstanceMethods
|
15
16
|
extend ClassMethods, Migration
|
@@ -23,7 +23,7 @@ module Globalize
|
|
23
23
|
Globalize.fallbacks(locale).each do |fallback|
|
24
24
|
value = fetch_stash(fallback, name) || fetch_attribute(fallback, name)
|
25
25
|
|
26
|
-
|
26
|
+
unless fallbacks_for?(value)
|
27
27
|
set_metadata(value, :locale => fallback, :requested_locale => locale)
|
28
28
|
return value
|
29
29
|
end
|
@@ -41,6 +41,7 @@ module Globalize
|
|
41
41
|
attrs.each { |name, value| translation[name] = value }
|
42
42
|
translation.save!
|
43
43
|
end
|
44
|
+
record.translations.each(&:reload)
|
44
45
|
record.translations.reset
|
45
46
|
stash.clear
|
46
47
|
end
|
@@ -84,6 +85,14 @@ module Globalize
|
|
84
85
|
class << object; attr_accessor :translation_metadata end
|
85
86
|
object.translation_metadata ||= {}
|
86
87
|
end
|
88
|
+
|
89
|
+
def fallbacks_for?(object)
|
90
|
+
object.nil? || (fallbacks_for_empty_translations? && object.blank?)
|
91
|
+
end
|
92
|
+
|
93
|
+
def fallbacks_for_empty_translations?
|
94
|
+
record.fallbacks_for_empty_translations
|
95
|
+
end
|
87
96
|
end
|
88
97
|
end
|
89
98
|
end
|
@@ -113,7 +113,9 @@ module Globalize
|
|
113
113
|
def translation_for(locale)
|
114
114
|
@translation_caches ||= {}
|
115
115
|
unless @translation_caches[locale]
|
116
|
-
|
116
|
+
# Enumberable#detect is better since we have the translations collection (already) loaded
|
117
|
+
# using either Model.includes(:translations) or Model.with_translations
|
118
|
+
_translation = translations.detect{|t| t.locale.to_s == locale.to_s}
|
117
119
|
_translation ||= translations.build(:locale => locale)
|
118
120
|
@translation_caches[locale] = _translation
|
119
121
|
end
|
data/lib/globalize3/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 62196357
|
4
5
|
prerelease: 6
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
- 3
|
12
|
+
version: 0.2.0.beta3
|
6
13
|
platform: ruby
|
7
14
|
authors:
|
8
15
|
- Sven Fuchs
|
@@ -13,8 +20,7 @@ autorequire:
|
|
13
20
|
bindir: bin
|
14
21
|
cert_chain: []
|
15
22
|
|
16
|
-
date: 2011-
|
17
|
-
default_executable:
|
23
|
+
date: 2011-08-16 00:00:00 Z
|
18
24
|
dependencies:
|
19
25
|
- !ruby/object:Gem::Dependency
|
20
26
|
name: activerecord
|
@@ -24,6 +30,11 @@ dependencies:
|
|
24
30
|
requirements:
|
25
31
|
- - ">="
|
26
32
|
- !ruby/object:Gem::Version
|
33
|
+
hash: 7
|
34
|
+
segments:
|
35
|
+
- 3
|
36
|
+
- 0
|
37
|
+
- 0
|
27
38
|
version: 3.0.0
|
28
39
|
type: :runtime
|
29
40
|
version_requirements: *id001
|
@@ -35,6 +46,11 @@ dependencies:
|
|
35
46
|
requirements:
|
36
47
|
- - ">="
|
37
48
|
- !ruby/object:Gem::Version
|
49
|
+
hash: 7
|
50
|
+
segments:
|
51
|
+
- 3
|
52
|
+
- 0
|
53
|
+
- 0
|
38
54
|
version: 3.0.0
|
39
55
|
type: :runtime
|
40
56
|
version_requirements: *id002
|
@@ -46,6 +62,9 @@ dependencies:
|
|
46
62
|
requirements:
|
47
63
|
- - ~>
|
48
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 7
|
66
|
+
segments:
|
67
|
+
- 2
|
49
68
|
version: "2"
|
50
69
|
type: :runtime
|
51
70
|
version_requirements: *id003
|
@@ -57,6 +76,11 @@ dependencies:
|
|
57
76
|
requirements:
|
58
77
|
- - "="
|
59
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 15
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
- 5
|
83
|
+
- 2
|
60
84
|
version: 0.5.2
|
61
85
|
type: :development
|
62
86
|
version_requirements: *id004
|
@@ -68,6 +92,9 @@ dependencies:
|
|
68
92
|
requirements:
|
69
93
|
- - ">="
|
70
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
71
98
|
version: "0"
|
72
99
|
type: :development
|
73
100
|
version_requirements: *id005
|
@@ -79,6 +106,9 @@ dependencies:
|
|
79
106
|
requirements:
|
80
107
|
- - ">="
|
81
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
82
112
|
version: "0"
|
83
113
|
type: :development
|
84
114
|
version_requirements: *id006
|
@@ -90,17 +120,23 @@ dependencies:
|
|
90
120
|
requirements:
|
91
121
|
- - ">="
|
92
122
|
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
93
126
|
version: "0"
|
94
127
|
type: :development
|
95
128
|
version_requirements: *id007
|
96
129
|
- !ruby/object:Gem::Dependency
|
97
|
-
name: ruby-
|
130
|
+
name: ruby-debug
|
98
131
|
prerelease: false
|
99
132
|
requirement: &id008 !ruby/object:Gem::Requirement
|
100
133
|
none: false
|
101
134
|
requirements:
|
102
135
|
- - ">="
|
103
136
|
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
104
140
|
version: "0"
|
105
141
|
type: :development
|
106
142
|
version_requirements: *id008
|
@@ -112,6 +148,9 @@ dependencies:
|
|
112
148
|
requirements:
|
113
149
|
- - ">="
|
114
150
|
- !ruby/object:Gem::Version
|
151
|
+
hash: 3
|
152
|
+
segments:
|
153
|
+
- 0
|
115
154
|
version: "0"
|
116
155
|
type: :development
|
117
156
|
version_requirements: *id009
|
@@ -147,7 +186,6 @@ files:
|
|
147
186
|
- LICENSE
|
148
187
|
- Rakefile
|
149
188
|
- README.textile
|
150
|
-
has_rdoc: true
|
151
189
|
homepage: http://github.com/svenfuchs/globalize3
|
152
190
|
licenses: []
|
153
191
|
|
@@ -161,17 +199,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
199
|
requirements:
|
162
200
|
- - ">="
|
163
201
|
- !ruby/object:Gem::Version
|
202
|
+
hash: 3
|
203
|
+
segments:
|
204
|
+
- 0
|
164
205
|
version: "0"
|
165
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
207
|
none: false
|
167
208
|
requirements:
|
168
209
|
- - ">"
|
169
210
|
- !ruby/object:Gem::Version
|
211
|
+
hash: 25
|
212
|
+
segments:
|
213
|
+
- 1
|
214
|
+
- 3
|
215
|
+
- 1
|
170
216
|
version: 1.3.1
|
171
217
|
requirements: []
|
172
218
|
|
173
219
|
rubyforge_project: "[none]"
|
174
|
-
rubygems_version: 1.6
|
220
|
+
rubygems_version: 1.8.6
|
175
221
|
signing_key:
|
176
222
|
specification_version: 3
|
177
223
|
summary: "Rails I18n: de-facto standard library for ActiveRecord 3 model/data translation"
|