gettext_i18n_rails 0.9.4 → 0.10.0
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.
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -1
- data/Readme.md +2 -0
- data/gemfiles/rails.2.3.gemfile.lock +1 -1
- data/gemfiles/rails.3.0.gemfile.lock +1 -1
- data/gemfiles/rails.3.1.gemfile.lock +1 -1
- data/gemfiles/rails.3.2.gemfile.lock +1 -1
- data/lib/gettext_i18n_rails/active_model/translation.rb +7 -1
- data/lib/gettext_i18n_rails/model_attributes_finder.rb +24 -11
- data/lib/gettext_i18n_rails/version.rb +1 -1
- data/spec/gettext_i18n_rails/active_record_spec.rb +10 -0
- data/spec/gettext_i18n_rails/model_attributes_finder_spec.rb +8 -2
- data/spec/spec_helper.rb +22 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'bundler/setup'
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'appraisal'
|
3
4
|
require 'bump/tasks'
|
@@ -7,5 +8,5 @@ task :spec do
|
|
7
8
|
end
|
8
9
|
|
9
10
|
task :default do
|
10
|
-
sh "
|
11
|
+
sh "rake appraisal:install && rake appraisal spec"
|
11
12
|
end
|
data/Readme.md
CHANGED
@@ -233,6 +233,8 @@ If want to use your .PO files on client side javascript you should have a look a
|
|
233
233
|
- [Ivan Necas](https://github.com/iNecas)
|
234
234
|
- [Andrey Chernih](https://github.com/AndreyChernyh)
|
235
235
|
- [Imre Farkas](https://github.com/ifarkas)
|
236
|
+
- [Trong Tran](https://github.com/trongrg)
|
237
|
+
- [Dmitri Dolguikh](https://github.com/witlessbird)
|
236
238
|
|
237
239
|
[Michael Grosser](http://grosser.it)<br/>
|
238
240
|
grosser.michael@gmail.com<br/>
|
@@ -10,10 +10,16 @@ module ActiveModel
|
|
10
10
|
if attribute.ends_with?('_id')
|
11
11
|
humanize_class_name(attribute)
|
12
12
|
else
|
13
|
-
"#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
|
13
|
+
"#{inheritance_tree_root(self)}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def inheritance_tree_root(aclass)
|
18
|
+
return aclass unless aclass.respond_to?(:base_class)
|
19
|
+
base = aclass.base_class
|
20
|
+
base.superclass.abstract_class? ? base.superclass : base
|
21
|
+
end
|
22
|
+
|
17
23
|
def humanize_class_name(name=nil)
|
18
24
|
name ||= self.to_s
|
19
25
|
name.underscore.humanize
|
@@ -34,27 +34,40 @@ module GettextI18nRails
|
|
34
34
|
# current connection ---> {'cars'=>['model_name','type'],...}
|
35
35
|
def find(options)
|
36
36
|
found = ActiveSupport::OrderedHash.new([])
|
37
|
-
|
38
37
|
models.each do |model|
|
39
|
-
|
40
|
-
|
41
|
-
next if ignored?(table_name,options[:ignore_tables])
|
42
|
-
model.columns.each do |column|
|
43
|
-
found[model] += [column.name] unless ignored?(column.name,options[:ignore_columns])
|
44
|
-
end
|
45
|
-
found[model].sort!
|
38
|
+
attributes = model_attributes(model, options[:ignore_tables], options[:ignore_columns])
|
39
|
+
found[model] = attributes.sort if attributes.any?
|
46
40
|
end
|
47
|
-
|
48
41
|
found
|
49
42
|
end
|
50
43
|
|
44
|
+
# Rails < 3.0 doesn't have DescendantsTracker.
|
45
|
+
# Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
|
46
|
+
# class hierarchies with abstract base classes in Rails 2.x
|
47
|
+
def model_attributes(model, ignored_tables, ignored_cols)
|
48
|
+
return [] if model.abstract_class? && Rails::VERSION::MAJOR < 3
|
49
|
+
|
50
|
+
if model.abstract_class?
|
51
|
+
model.direct_descendants.reject {|m| ignored?(m.table_name, ignored_tables)}.inject([]) do |attrs, m|
|
52
|
+
attrs.push(model_attributes(m, ignored_tables, ignored_cols)).flatten.uniq
|
53
|
+
end
|
54
|
+
elsif !ignored?(model.table_name, ignored_tables)
|
55
|
+
model.columns.reject { |c| ignored?(c.name, ignored_cols) }.collect { |c| c.name }
|
56
|
+
else
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
51
61
|
def models
|
52
62
|
if Rails::VERSION::MAJOR > 2
|
53
63
|
Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
|
54
64
|
::ActiveRecord::Base.direct_descendants
|
55
65
|
else
|
56
|
-
::ActiveRecord::Base.connection.tables
|
57
|
-
|
66
|
+
::ActiveRecord::Base.connection.tables \
|
67
|
+
.map { |t| table_name_to_namespaced_model(t) } \
|
68
|
+
.compact \
|
69
|
+
.collect { |c| c.superclass.abstract_class? ? c.superclass : c }
|
70
|
+
end.uniq.sort_by(&:name)
|
58
71
|
end
|
59
72
|
|
60
73
|
def ignored?(name,patterns)
|
@@ -23,6 +23,16 @@ describe ActiveRecord::Base do
|
|
23
23
|
CarSeat.should_receive(:s_).with('CarSeat|Parts|Name').and_return('Handle')
|
24
24
|
CarSeat.human_attribute_name(:"parts.name").should == 'Handle'
|
25
25
|
end
|
26
|
+
|
27
|
+
it "translates attributes of STI classes through FastGettext" do
|
28
|
+
StiChild.should_receive(:s_).with('StiParent|Child attribute').and_return('Kinderattribut')
|
29
|
+
StiChild.human_attribute_name(:child_attribute).should == 'Kinderattribut'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "translates attributes of concrete children of abstract parent classes" do
|
33
|
+
ConcreteChildClass.should_receive(:s_).with('AbstractParentClass|Child attribute').and_return('Kinderattribut')
|
34
|
+
ConcreteChildClass.human_attribute_name(:child_attribute).should == 'Kinderattribut'
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
describe :gettext_translation_for_attribute_name do
|
@@ -16,13 +16,16 @@ describe GettextI18nRails::ModelAttributesFinder do
|
|
16
16
|
Rails.application rescue nil
|
17
17
|
end
|
18
18
|
|
19
|
+
# Rails < 3.0 doesn't have DescendantsTracker.
|
20
|
+
# Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
|
21
|
+
# class hierarchies with abstract base classes in Rails 2.x
|
19
22
|
describe :find do
|
20
23
|
it "returns all AR models" do
|
21
24
|
keys = finder.find({}).keys
|
22
25
|
if Rails::VERSION::MAJOR > 2
|
23
|
-
keys.should == [CarSeat, NotConventional, Part]
|
26
|
+
keys.should == [AbstractParentClass, CarSeat, NotConventional, Part, StiParent]
|
24
27
|
else
|
25
|
-
keys.should == [CarSeat, Part]
|
28
|
+
keys.should == [CarSeat, Part, StiParent]
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -31,6 +34,9 @@ describe GettextI18nRails::ModelAttributesFinder do
|
|
31
34
|
attributes[CarSeat].should == ['id', 'seat_color']
|
32
35
|
attributes[NotConventional].should == ['id', 'name'] if Rails::VERSION::MAJOR > 2
|
33
36
|
attributes[Part].should == ['car_seat_id', 'id', 'name']
|
37
|
+
attributes[StiParent].should == ['child_attribute', 'id', 'type']
|
38
|
+
attributes[AbstractParentClass].should ==
|
39
|
+
['another_child_attribute', 'child_attribute', 'id'] if Rails::VERSION::MAJOR > 2
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -66,6 +66,19 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
66
66
|
create_table :not_at_all_conventionals, :force=>true do |t|
|
67
67
|
t.string :name
|
68
68
|
end
|
69
|
+
|
70
|
+
create_table :sti_parents, :force => true do |t|
|
71
|
+
t.string :type
|
72
|
+
t.string :child_attribute
|
73
|
+
end
|
74
|
+
|
75
|
+
create_table :concrete_child_classes, :force => true do |t|
|
76
|
+
t.string :child_attribute
|
77
|
+
end
|
78
|
+
|
79
|
+
create_table :other_concrete_child_classes, :force => true do |t|
|
80
|
+
t.string :another_child_attribute
|
81
|
+
end
|
69
82
|
end
|
70
83
|
|
71
84
|
class CarSeat < ActiveRecord::Base
|
@@ -78,6 +91,15 @@ class Part < ActiveRecord::Base
|
|
78
91
|
belongs_to :car_seat
|
79
92
|
end
|
80
93
|
|
94
|
+
class StiParent < ActiveRecord::Base; end
|
95
|
+
class StiChild < StiParent; end
|
96
|
+
|
97
|
+
class AbstractParentClass < ActiveRecord::Base
|
98
|
+
self.abstract_class = true
|
99
|
+
end
|
100
|
+
class ConcreteChildClass < AbstractParentClass; end
|
101
|
+
class OtherConcreteChildClass < AbstractParentClass; end
|
102
|
+
|
81
103
|
class NotConventional < ActiveRecord::Base
|
82
104
|
if ActiveRecord::VERSION::MAJOR == 3
|
83
105
|
self.table_name = :not_at_all_conventionals
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_i18n_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fast_gettext
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
segments:
|
105
105
|
- 0
|
106
|
-
hash:
|
106
|
+
hash: -2644697753242804887
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: -2644697753242804887
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
118
|
rubygems_version: 1.8.25
|