gettext_column_mapping 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/gettext_column_mapping.gemspec +16 -15
- data/lib/gettext_column_mapping/mapper.rb +1 -1
- data/lib/gettext_column_mapping/model_attributes_finder.rb +20 -13
- data/lib/gettext_column_mapping/parent_level.rb +7 -3
- data/lib/gettext_column_mapping/version.rb +3 -0
- data/lib/gettext_column_mapping.rb +1 -0
- data/test/activerecord_test.rb +1 -3
- data/test/gettext_column_mapping_test.rb +1 -1
- data/test/mapper_test.rb +7 -2
- data/test/test_helper.rb +6 -1
- metadata +16 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gettext_column_mapping}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["hallelujah"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-07}
|
13
13
|
s.description = %q{Translate your database columns with gettext}
|
14
14
|
s.email = %q{hery@rails-royce.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/gettext_column_mapping/parser/yaml.rb",
|
40
40
|
"lib/gettext_column_mapping/railtie.rb",
|
41
41
|
"lib/gettext_column_mapping/tasks.rb",
|
42
|
+
"lib/gettext_column_mapping/version.rb",
|
42
43
|
"tasks/gettext_column_mapping.rake",
|
43
44
|
"test/.gitignore",
|
44
45
|
"test/activerecord_test.rb",
|
@@ -73,22 +74,22 @@ Gem::Specification.new do |s|
|
|
73
74
|
s.rubygems_version = %q{1.3.7}
|
74
75
|
s.summary = %q{Translate your database columns with gettext}
|
75
76
|
s.test_files = [
|
76
|
-
"test/
|
77
|
-
"test/static/data.rb",
|
78
|
-
"test/static/pluralization.rb",
|
79
|
-
"test/activerecord_test.rb",
|
80
|
-
"test/mapper_test.rb",
|
77
|
+
"test/gettext_column_mapping_test.rb",
|
81
78
|
"test/fast_gettext_helper.rb",
|
82
|
-
"test/
|
83
|
-
"test/
|
84
|
-
"test/
|
85
|
-
"test/db/migrate/001_create_utilisateurs.rb",
|
86
|
-
"test/db/migrate/003_create_categories.rb",
|
87
|
-
"test/db/migrate/002_create_rubriques.rb",
|
88
|
-
"test/models/categorie.rb",
|
79
|
+
"test/test_helper.rb",
|
80
|
+
"test/static/pluralization.rb",
|
81
|
+
"test/static/data.rb",
|
89
82
|
"test/models/rubrique.rb",
|
90
83
|
"test/models/utilisateur.rb",
|
91
|
-
"test/
|
84
|
+
"test/models/categorie.rb",
|
85
|
+
"test/db/migrate/002_create_rubriques.rb",
|
86
|
+
"test/db/migrate/001_create_utilisateurs.rb",
|
87
|
+
"test/db/migrate/003_create_categories.rb",
|
88
|
+
"test/gettext_helper.rb",
|
89
|
+
"test/helper.rb",
|
90
|
+
"test/activerecord_test.rb",
|
91
|
+
"test/mapper_test.rb",
|
92
|
+
"test/extend_lib_path.rb"
|
92
93
|
]
|
93
94
|
|
94
95
|
if s.respond_to? :specification_version then
|
@@ -17,12 +17,12 @@ module GettextColumnMapping
|
|
17
17
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
18
18
|
ModelAttributesFinder.new.find(options).each do |model,column_names|
|
19
19
|
|
20
|
-
f.puts("s_(
|
20
|
+
f.puts("s_(\"#{model.to_s_with_gettext}\")") #!Keep in sync with ActiveRecord::Base.human_name
|
21
21
|
|
22
22
|
#all columns namespaced under the model
|
23
23
|
column_names.each do |attribute|
|
24
24
|
translation = model.gettext_translation_for_attribute_name(attribute)
|
25
|
-
f.puts("s_(
|
25
|
+
f.puts("s_(\"#{translation}\")")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
if GettextColumnMapping.config.use_parent_level
|
@@ -30,12 +30,15 @@ module GettextColumnMapping
|
|
30
30
|
GettextColumnMapping::ParentLevel.each_config do |klass_name,columns,parent_association,parent_key,conditions|
|
31
31
|
model = klass_name.constantize
|
32
32
|
options_hash = {}
|
33
|
+
if conditions
|
34
|
+
options_hash.merge!(:conditions => conditions)
|
35
|
+
end
|
33
36
|
if parent_association
|
34
|
-
|
37
|
+
options_hash.merge!( :include => parent_association)
|
35
38
|
end
|
36
|
-
model.find_each do |record|
|
39
|
+
model.find_each(options_hash) do |record|
|
37
40
|
columns.each do |column|
|
38
|
-
f.puts("s_(
|
41
|
+
f.puts("s_(\"#{record.msgid_for_attribute(column)}\")")
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -55,7 +58,7 @@ module GettextColumnMapping
|
|
55
58
|
#all columns namespaced under the model
|
56
59
|
column_names.each do |attribute|
|
57
60
|
translation = model.gettext_translation_for_attribute_name(attribute)
|
58
|
-
f.puts("s_(
|
61
|
+
f.puts("s_(\"#{translation}\")")
|
59
62
|
end
|
60
63
|
|
61
64
|
if GettextColumnMapping.config.use_parent_level
|
@@ -63,18 +66,21 @@ module GettextColumnMapping
|
|
63
66
|
GettextColumnMapping::ParentLevel.item_config(model.name) do |klass_name,columns,parent_association,parent_key,conditions|
|
64
67
|
model = klass_name.constantize
|
65
68
|
options_hash = {}
|
69
|
+
if conditions
|
70
|
+
options_hash.merge!(:conditions => conditions)
|
71
|
+
end
|
66
72
|
if parent_association
|
67
|
-
options_hash.merge!(
|
73
|
+
options_hash.merge!( :include => parent_association)
|
68
74
|
end
|
69
|
-
model.find_each do |record|
|
70
|
-
columns.each do |
|
71
|
-
f.puts("s_(
|
75
|
+
model.find_each(options_hash) do |record|
|
76
|
+
columns.each do |key|
|
77
|
+
f.puts("s_(\"#{record.msgid_for_attribute(key)}\")")
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
75
|
-
|
81
|
+
end
|
76
82
|
|
77
|
-
|
83
|
+
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
78
84
|
|
79
85
|
end
|
80
86
|
end
|
@@ -107,7 +113,8 @@ module GettextColumnMapping
|
|
107
113
|
found = Hash.new([])
|
108
114
|
|
109
115
|
GettextColumnMapping.activerecord_subclasses.each do |subclass|
|
110
|
-
next if
|
116
|
+
next if table_ignored?(subclass,options[:ignore_tables])
|
117
|
+
found[subclass] = [] if GettextColumnMapping.config.use_parent_level && ! GettextColumnMapping::ParentLevel.column_attributes_translation(subclass.name).blank?
|
111
118
|
subclass.columns.each do |column|
|
112
119
|
unless column_ignored?(subclass,column,options[:ignore_columns])
|
113
120
|
found[subclass] += [column.name]
|
@@ -33,8 +33,8 @@ module GettextColumnMapping
|
|
33
33
|
def prefix(klass = nil,column = nil,parent = nil,key = nil)
|
34
34
|
prefixes = [data_prefix]
|
35
35
|
prefixes << "#{klass.to_s_with_gettext}" if klass
|
36
|
-
prefixes
|
37
|
-
prefixes <<
|
36
|
+
prefixes << parent[key] if parent
|
37
|
+
prefixes << klass.column_map_attribute(column.to_s) if column
|
38
38
|
prefixes.join("|")
|
39
39
|
end
|
40
40
|
|
@@ -58,13 +58,17 @@ module GettextColumnMapping
|
|
58
58
|
if parent
|
59
59
|
parent_key = parent[:key]
|
60
60
|
parent_association = parent[:association]
|
61
|
-
conditions = parent[:conditions]
|
62
61
|
end
|
62
|
+
conditions = conditions_translation(klass_name)
|
63
63
|
results = [klass_name,columns,parent_association,parent_key,conditions]
|
64
64
|
yield(*results) if block_given?
|
65
65
|
results
|
66
66
|
end
|
67
67
|
|
68
|
+
def conditions_translation(klass_name)
|
69
|
+
attributes_translation(klass_name) && attributes_translation(klass_name)[:conditions]
|
70
|
+
end
|
71
|
+
|
68
72
|
def attributes_translation(klass_name)
|
69
73
|
@attributes_translation[klass_name] = @parent_level_config[klass_name.underscore]
|
70
74
|
end
|
data/test/activerecord_test.rb
CHANGED
data/test/mapper_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'test_helper'
|
3
|
-
|
4
|
-
|
3
|
+
class UtilisateurTest < ActiveSupport::TestCase
|
4
|
+
fixtures :categories, :rubriques
|
5
5
|
|
6
6
|
class NotMapped < ActiveRecord::Base; end
|
7
7
|
|
@@ -27,6 +27,11 @@ class UtilisateurTest < Test::Unit::TestCase
|
|
27
27
|
assert GettextColumnMapping.mapper.translate_class_name?(Utilisateur)
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_map_attribute
|
31
|
+
assert 'Label', GettextColumnMapping.mapper.map_attribute(NotMapped,'label')
|
32
|
+
assert 'Label', GettextColumnMapping.mapper.map_attribute(Categorie,'label')
|
33
|
+
end
|
34
|
+
|
30
35
|
def test_translation
|
31
36
|
GettextColumnMapping.locale = 'en'
|
32
37
|
assert_equal 'User', Utilisateur.human_name
|
data/test/test_helper.rb
CHANGED
@@ -4,8 +4,13 @@ if ENV['GETTEXT']
|
|
4
4
|
else
|
5
5
|
require 'fast_gettext_helper'
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
|
+
require 'models/utilisateur'
|
9
|
+
require 'models/categorie'
|
10
|
+
require 'models/rubrique'
|
11
|
+
|
8
12
|
require 'active_support/test_case'
|
13
|
+
require 'test/unit'
|
9
14
|
class ActiveSupport::TestCase
|
10
15
|
include ActiveRecord::TestFixtures
|
11
16
|
self.fixture_path = File.expand_path("../db/fixtures",__FILE__)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- hallelujah
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/gettext_column_mapping/parser/yaml.rb
|
51
51
|
- lib/gettext_column_mapping/railtie.rb
|
52
52
|
- lib/gettext_column_mapping/tasks.rb
|
53
|
+
- lib/gettext_column_mapping/version.rb
|
53
54
|
- tasks/gettext_column_mapping.rake
|
54
55
|
- test/.gitignore
|
55
56
|
- test/activerecord_test.rb
|
@@ -110,19 +111,19 @@ signing_key:
|
|
110
111
|
specification_version: 3
|
111
112
|
summary: Translate your database columns with gettext
|
112
113
|
test_files:
|
113
|
-
- test/
|
114
|
-
- test/
|
114
|
+
- test/gettext_column_mapping_test.rb
|
115
|
+
- test/fast_gettext_helper.rb
|
116
|
+
- test/test_helper.rb
|
115
117
|
- test/static/pluralization.rb
|
118
|
+
- test/static/data.rb
|
119
|
+
- test/models/rubrique.rb
|
120
|
+
- test/models/utilisateur.rb
|
121
|
+
- test/models/categorie.rb
|
122
|
+
- test/db/migrate/002_create_rubriques.rb
|
123
|
+
- test/db/migrate/001_create_utilisateurs.rb
|
124
|
+
- test/db/migrate/003_create_categories.rb
|
125
|
+
- test/gettext_helper.rb
|
126
|
+
- test/helper.rb
|
116
127
|
- test/activerecord_test.rb
|
117
128
|
- test/mapper_test.rb
|
118
|
-
- test/fast_gettext_helper.rb
|
119
|
-
- test/gettext_column_mapping_test.rb
|
120
129
|
- test/extend_lib_path.rb
|
121
|
-
- test/gettext_helper.rb
|
122
|
-
- test/db/migrate/001_create_utilisateurs.rb
|
123
|
-
- test/db/migrate/003_create_categories.rb
|
124
|
-
- test/db/migrate/002_create_rubriques.rb
|
125
|
-
- test/models/categorie.rb
|
126
|
-
- test/models/rubrique.rb
|
127
|
-
- test/models/utilisateur.rb
|
128
|
-
- test/test_helper.rb
|