gettext_i18n_rails 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +10 -14
- data/Gemfile.lock +7 -7
- data/Rakefile +17 -12
- data/Readme.md +1 -0
- data/gettext_i18n_rails.gemspec +10 -62
- data/lib/gettext_i18n_rails/active_model.rb +7 -0
- data/lib/gettext_i18n_rails/active_record.rb +9 -4
- data/lib/gettext_i18n_rails/model_attributes_finder.rb +61 -55
- data/lib/gettext_i18n_rails/railtie.rb +4 -0
- data/lib/gettext_i18n_rails/version.rb +3 -0
- data/lib/gettext_i18n_rails.rb +6 -2
- data/spec/gettext_i18n_rails/active_model_spec.rb +16 -0
- data/spec/gettext_i18n_rails/active_record_spec.rb +7 -31
- data/spec/gettext_i18n_rails/model_attributes_finder_spec.rb +36 -0
- data/spec/spec_helper.rb +37 -1
- metadata +54 -31
- data/VERSION +0 -1
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
source :rubygems
|
2
|
+
gemspec
|
2
3
|
|
3
|
-
gem '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem 'rails', ENV['RAILS'] || '~>3'
|
13
|
-
gem 'rake'
|
14
|
-
gem 'rspec', '~>2'
|
15
|
-
gem 'jeweler'
|
16
|
-
end
|
4
|
+
gem 'haml'
|
5
|
+
gem 'slim'
|
6
|
+
gem 'hamlet'
|
7
|
+
gem 'ruby_parser'
|
8
|
+
gem 'gettext'
|
9
|
+
gem 'sqlite3', '~>1.3.4'
|
10
|
+
gem 'rails', ENV['RAILS'] || '~>3'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rspec', '~>2'
|
data/Gemfile.lock
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gettext_i18n_rails (0.5.0)
|
5
|
+
fast_gettext
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
@@ -38,16 +44,11 @@ GEM
|
|
38
44
|
fast_gettext (0.5.13)
|
39
45
|
gettext (2.1.0)
|
40
46
|
locale (>= 2.0.5)
|
41
|
-
git (1.2.5)
|
42
47
|
haml (3.1.4)
|
43
48
|
hamlet (0.1)
|
44
49
|
slim (~> 1.0)
|
45
50
|
hike (1.2.1)
|
46
51
|
i18n (0.6.0)
|
47
|
-
jeweler (1.6.4)
|
48
|
-
bundler (~> 1.0)
|
49
|
-
git (>= 1.2.5)
|
50
|
-
rake
|
51
52
|
locale (2.0.5)
|
52
53
|
mail (2.3.0)
|
53
54
|
i18n (>= 0.4.0)
|
@@ -113,11 +114,10 @@ PLATFORMS
|
|
113
114
|
ruby
|
114
115
|
|
115
116
|
DEPENDENCIES
|
116
|
-
fast_gettext
|
117
117
|
gettext
|
118
|
+
gettext_i18n_rails!
|
118
119
|
haml
|
119
120
|
hamlet
|
120
|
-
jeweler
|
121
121
|
rails (~> 3)
|
122
122
|
rake
|
123
123
|
rspec (~> 2)
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
1
3
|
task :spec do
|
2
4
|
sh "rspec spec"
|
3
5
|
end
|
@@ -8,17 +10,20 @@ task :default do
|
|
8
10
|
sh "RAILS=3.1.0 && (bundle || bundle install) && bundle exec rake spec"
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
# extracted from https://github.com/grosser/project_template
|
14
|
+
rule /^version:bump:.*/ do |t|
|
15
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
16
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
17
|
+
file = 'lib/gettext_i18n_rails/version.rb'
|
18
|
+
|
19
|
+
version_file = File.read(file)
|
20
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
21
|
+
version_parts[index] = version_parts[index].to_i + 1
|
22
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
23
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
24
|
+
new_version = version_parts * '.'
|
25
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
20
26
|
|
21
|
-
|
22
|
-
rescue LoadError
|
23
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
27
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
24
28
|
end
|
29
|
+
|
data/Readme.md
CHANGED
@@ -220,6 +220,7 @@ lib/tasks/gettext.rake:
|
|
220
220
|
- [Lucas Hills](https://github.com/2potatocakes)
|
221
221
|
- [Ladislav Slezák](https://github.com/lslezak)
|
222
222
|
- [Greg Weber](https://github.com/gregwebs)
|
223
|
+
- [Sean Kirby](https://github.com/sskirby)
|
223
224
|
|
224
225
|
[Michael Grosser](http://grosser.it)<br/>
|
225
226
|
grosser.michael@gmail.com<br/>
|
data/gettext_i18n_rails.gemspec
CHANGED
@@ -1,65 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
name = "gettext_i18n_rails"
|
3
|
+
require "#{name}/version"
|
5
4
|
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "gettext_i18n_rails"
|
8
|
-
s.version = "0.4.6"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = "2012-04-05"
|
13
|
-
s.email = "grosser.michael@gmail.com"
|
14
|
-
s.files = [
|
15
|
-
"Gemfile",
|
16
|
-
"Gemfile.lock",
|
17
|
-
"Rakefile",
|
18
|
-
"Readme.md",
|
19
|
-
"VERSION",
|
20
|
-
"gettext_i18n_rails.gemspec",
|
21
|
-
"init.rb",
|
22
|
-
"lib/gettext_i18n_rails.rb",
|
23
|
-
"lib/gettext_i18n_rails/action_controller.rb",
|
24
|
-
"lib/gettext_i18n_rails/active_record.rb",
|
25
|
-
"lib/gettext_i18n_rails/backend.rb",
|
26
|
-
"lib/gettext_i18n_rails/base_parser.rb",
|
27
|
-
"lib/gettext_i18n_rails/haml_parser.rb",
|
28
|
-
"lib/gettext_i18n_rails/hamlet_parser.rb",
|
29
|
-
"lib/gettext_i18n_rails/html_safe_translations.rb",
|
30
|
-
"lib/gettext_i18n_rails/i18n_hacks.rb",
|
31
|
-
"lib/gettext_i18n_rails/model_attributes_finder.rb",
|
32
|
-
"lib/gettext_i18n_rails/railtie.rb",
|
33
|
-
"lib/gettext_i18n_rails/ruby_gettext_extractor.rb",
|
34
|
-
"lib/gettext_i18n_rails/slim_parser.rb",
|
35
|
-
"lib/gettext_i18n_rails/string_interpolate_fix.rb",
|
36
|
-
"lib/gettext_i18n_rails/tasks.rb",
|
37
|
-
"lib/tasks/gettext_rails_i18n.rake",
|
38
|
-
"spec/gettext_i18n_rails/action_controller_spec.rb",
|
39
|
-
"spec/gettext_i18n_rails/active_record_spec.rb",
|
40
|
-
"spec/gettext_i18n_rails/backend_spec.rb",
|
41
|
-
"spec/gettext_i18n_rails/haml_parser_spec.rb",
|
42
|
-
"spec/gettext_i18n_rails/hamlet_parser_spec.rb",
|
43
|
-
"spec/gettext_i18n_rails/slim_parser_spec.rb",
|
44
|
-
"spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
|
45
|
-
"spec/gettext_i18n_rails_spec.rb",
|
46
|
-
"spec/spec_helper.rb"
|
47
|
-
]
|
48
|
-
s.homepage = "http://github.com/grosser/gettext_i18n_rails"
|
49
|
-
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = "1.8.15"
|
5
|
+
Gem::Specification.new name, GettextI18nRails::VERSION do |s|
|
51
6
|
s.summary = "Simple FastGettext Rails integration."
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
60
|
-
end
|
61
|
-
else
|
62
|
-
s.add_dependency(%q<fast_gettext>, [">= 0"])
|
63
|
-
end
|
7
|
+
s.authors = ["Michael Grosser"]
|
8
|
+
s.email = "michael@grosser.it"
|
9
|
+
s.homepage = "http://github.com/grosser/#{name}"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.license = "MIT"
|
12
|
+
s.add_runtime_dependency "fast_gettext"
|
64
13
|
end
|
65
|
-
|
@@ -5,15 +5,20 @@ module GettextI18nRails::ActiveRecord
|
|
5
5
|
end
|
6
6
|
|
7
7
|
# CarDealer -> _('car dealer')
|
8
|
+
# method deprecated in Rails 3.1
|
8
9
|
def human_name(*args)
|
9
|
-
_(self.
|
10
|
+
_(self.humanize_class_name(self.to_s))
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
|
13
|
+
def humanize_class_name(name)
|
14
|
+
name.underscore.humanize
|
14
15
|
end
|
15
16
|
|
16
17
|
def gettext_translation_for_attribute_name(attribute)
|
17
|
-
|
18
|
+
if attribute.to_s.ends_with?('_id')
|
19
|
+
humanize_class_name(attribute)
|
20
|
+
else
|
21
|
+
"#{self}|#{attribute.to_s.split('.').map! {|a| a.humanize }.join('|')}"
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'rails/version'
|
2
|
+
require 'rails' if Rails::VERSION::MAJOR > 2
|
3
|
+
|
1
4
|
module GettextI18nRails
|
2
5
|
#write all found models/columns to a file where GetTexts ruby parser can find them
|
3
6
|
def store_model_attributes(options)
|
@@ -5,14 +8,7 @@ module GettextI18nRails
|
|
5
8
|
begin
|
6
9
|
File.open(file,'w') do |f|
|
7
10
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
8
|
-
ModelAttributesFinder.new.find(options).each do |
|
9
|
-
#model name
|
10
|
-
model = table_name_to_namespaced_model(table_name)
|
11
|
-
if model == nil
|
12
|
-
# Some tables are not models, for example: translation tables created by globalize2.
|
13
|
-
puts "[Warning] Model not found for table '#{table_name}'"
|
14
|
-
next
|
15
|
-
end
|
11
|
+
ModelAttributesFinder.new.find(options).each do |model,column_names|
|
16
12
|
f.puts("_('#{model.human_name_without_translation}')")
|
17
13
|
|
18
14
|
#all columns namespaced under the model
|
@@ -37,72 +33,82 @@ module GettextI18nRails
|
|
37
33
|
# :ignore_columns => ['id',/_id$/,...]
|
38
34
|
# current connection ---> {'cars'=>['model_name','type'],...}
|
39
35
|
def find(options)
|
40
|
-
found =
|
36
|
+
found = ActiveSupport::OrderedHash.new([])
|
41
37
|
|
42
|
-
|
43
|
-
|
38
|
+
models.each do |model|
|
39
|
+
table_name = model.table_name
|
44
40
|
next if ignored?(table_name,options[:ignore_tables])
|
45
|
-
|
46
|
-
found[
|
41
|
+
model.columns.each do |column|
|
42
|
+
found[model] += [column.name] unless ignored?(column.name,options[:ignore_columns])
|
47
43
|
end
|
44
|
+
found[model].sort!
|
48
45
|
end
|
49
46
|
|
50
47
|
found
|
51
48
|
end
|
52
49
|
|
50
|
+
def models
|
51
|
+
if Rails::VERSION::MAJOR > 2
|
52
|
+
Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
|
53
|
+
::ActiveRecord::Base.direct_descendants
|
54
|
+
else
|
55
|
+
::ActiveRecord::Base.connection.tables.map {|t| table_name_to_namespaced_model(t) }
|
56
|
+
end.compact.sort {|c1, c2| c1.name <=> c2.name}
|
57
|
+
end
|
58
|
+
|
53
59
|
def ignored?(name,patterns)
|
54
60
|
return false unless patterns
|
55
61
|
patterns.detect{|p|p.to_s==name.to_s or (p.is_a?(Regexp) and name=~p)}
|
56
62
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
# Tries to find the model class corresponding to specified table name.
|
61
|
-
# Takes into account that the model can be defined in a namespace.
|
62
|
-
# Searches only up to one level deep - won't find models nested in two
|
63
|
-
# or more modules.
|
64
|
-
#
|
65
|
-
# Note that if we allow namespaces, the conversion can be ambiguous, i.e.
|
66
|
-
# if the table is named "aa_bb_cc" and AaBbCc, Aa::BbCc and AaBb::Cc are
|
67
|
-
# all defined there's no absolute rule that tells us which one to use.
|
68
|
-
# This method prefers the less nested one and, if there are two at
|
69
|
-
# the same level, the one with shorter module name.
|
70
|
-
def table_name_to_namespaced_model(table_name)
|
71
|
-
# First assume that there are no namespaces
|
72
|
-
model = to_class(table_name.singularize.camelcase)
|
73
|
-
return model if model != nil
|
74
63
|
|
75
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
64
|
+
private
|
65
|
+
# Tries to find the model class corresponding to specified table name.
|
66
|
+
# Takes into account that the model can be defined in a namespace.
|
67
|
+
# Searches only up to one level deep - won't find models nested in two
|
68
|
+
# or more modules.
|
69
|
+
#
|
70
|
+
# Note that if we allow namespaces, the conversion can be ambiguous, i.e.
|
71
|
+
# if the table is named "aa_bb_cc" and AaBbCc, Aa::BbCc and AaBb::Cc are
|
72
|
+
# all defined there's no absolute rule that tells us which one to use.
|
73
|
+
# This method prefers the less nested one and, if there are two at
|
74
|
+
# the same level, the one with shorter module name.
|
75
|
+
def table_name_to_namespaced_model(table_name)
|
76
|
+
# First assume that there are no namespaces
|
77
|
+
model = to_class(table_name.singularize.camelcase)
|
83
78
|
return model if model != nil
|
84
79
|
|
85
|
-
|
86
|
-
|
80
|
+
# If you were wrong, assume that the model is in a namespace.
|
81
|
+
# Iterate over the underscores and try to substitute each of them
|
82
|
+
# for a slash that camelcase() replaces with the scope operator (::).
|
83
|
+
underscore_position = table_name.index('_')
|
84
|
+
while underscore_position != nil
|
85
|
+
namespaced_table_name = table_name.dup
|
86
|
+
namespaced_table_name[underscore_position] = '/'
|
87
|
+
model = to_class(namespaced_table_name.singularize.camelcase)
|
88
|
+
return model if model != nil
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
return nil
|
91
|
-
end
|
90
|
+
underscore_position = table_name.index('_', underscore_position + 1)
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
def to_class(name)
|
96
|
-
# I wanted to use Module.const_defined?() here to avoid relying
|
97
|
-
# on exceptions for normal program flow but it's of no use.
|
98
|
-
# If class autoloading is enabled, the constant may be undefined
|
99
|
-
# but turn out to be present when we actually try to use it.
|
100
|
-
begin
|
101
|
-
constant = name.constantize
|
102
|
-
rescue NameError
|
93
|
+
# The model either is not defined or is buried more than one level
|
94
|
+
# deep in a module hierarchy
|
103
95
|
return nil
|
104
96
|
end
|
105
97
|
|
106
|
-
|
98
|
+
# Checks if there is a class of specified name and if so, returns
|
99
|
+
# the class object. Otherwise returns nil.
|
100
|
+
def to_class(name)
|
101
|
+
# I wanted to use Module.const_defined?() here to avoid relying
|
102
|
+
# on exceptions for normal program flow but it's of no use.
|
103
|
+
# If class autoloading is enabled, the constant may be undefined
|
104
|
+
# but turn out to be present when we actually try to use it.
|
105
|
+
begin
|
106
|
+
constant = name.constantize
|
107
|
+
rescue NameError
|
108
|
+
return nil
|
109
|
+
end
|
110
|
+
|
111
|
+
return constant.is_a?(Class) ? constant : nil
|
112
|
+
end
|
107
113
|
end
|
108
114
|
end
|
data/lib/gettext_i18n_rails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
require 'gettext_i18n_rails/version'
|
2
|
+
|
1
3
|
module GettextI18nRails
|
2
|
-
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
3
|
-
|
4
4
|
extend self
|
5
5
|
end
|
6
6
|
|
@@ -29,5 +29,9 @@ if not defined?(Rails::Railtie) and defined?(ActiveRecord)
|
|
29
29
|
ActiveRecord::Base.extend GettextI18nRails::ActiveRecord
|
30
30
|
end
|
31
31
|
|
32
|
+
if not defined?(Rails::Railtie) and defined?(ActiveModel)
|
33
|
+
require 'gettext_i18n_rails/active_model'
|
34
|
+
end
|
35
|
+
|
32
36
|
require 'gettext_i18n_rails/action_controller' if defined?(ActionController) # so that bundle console can work in a rails project
|
33
37
|
require 'gettext_i18n_rails/railtie'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe ActiveModel::Name do
|
5
|
+
before do
|
6
|
+
FastGettext.current_cache = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'human' do
|
10
|
+
it "is translated through FastGettext" do
|
11
|
+
name = ActiveModel::Name.new(CarSeat)
|
12
|
+
name.should_receive(:_).with('Car seat').and_return('Autositz')
|
13
|
+
name.human.should == 'Autositz'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,36 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
|
-
FastGettext.silence_errors
|
5
|
-
|
6
|
-
ActiveRecord::Base.establish_connection({
|
7
|
-
:adapter => "sqlite3",
|
8
|
-
:database => ":memory:",
|
9
|
-
})
|
10
|
-
|
11
|
-
ActiveRecord::Schema.define(:version => 1) do
|
12
|
-
create_table :car_seats, :force=>true do |t|
|
13
|
-
t.string :seat_color
|
14
|
-
end
|
15
|
-
|
16
|
-
create_table :parts, :force=>true do |t|
|
17
|
-
t.string :name
|
18
|
-
t.references :car_seat
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
ActiveRecord::Base.extend GettextI18nRails::ActiveRecord
|
23
|
-
|
24
|
-
class CarSeat < ActiveRecord::Base
|
25
|
-
validates_presence_of :seat_color, :message=>"translate me"
|
26
|
-
has_many :parts
|
27
|
-
accepts_nested_attributes_for :parts
|
28
|
-
end
|
29
|
-
|
30
|
-
class Part < ActiveRecord::Base
|
31
|
-
belongs_to :car_seat
|
32
|
-
end
|
33
|
-
|
34
4
|
describe ActiveRecord::Base do
|
35
5
|
before do
|
36
6
|
FastGettext.current_cache = {}
|
@@ -38,7 +8,7 @@ describe ActiveRecord::Base do
|
|
38
8
|
|
39
9
|
describe :human_name do
|
40
10
|
it "is translated through FastGettext" do
|
41
|
-
CarSeat.should_receive(:_).with('
|
11
|
+
CarSeat.should_receive(:_).with('Car seat').and_return('Autositz')
|
42
12
|
CarSeat.human_name.should == 'Autositz'
|
43
13
|
end
|
44
14
|
end
|
@@ -55,6 +25,12 @@ describe ActiveRecord::Base do
|
|
55
25
|
end
|
56
26
|
end
|
57
27
|
|
28
|
+
describe :gettext_translation_for_attribute_name do
|
29
|
+
it "translates foreign keys to model name keys" do
|
30
|
+
Part.gettext_translation_for_attribute_name('car_seat_id').should == 'Car seat'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
58
34
|
describe 'error messages' do
|
59
35
|
let(:model){
|
60
36
|
c = CarSeat.new
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "gettext_i18n_rails/model_attributes_finder"
|
4
|
+
|
5
|
+
if Rails::VERSION::MAJOR > 2
|
6
|
+
module Test
|
7
|
+
class Application < Rails::Application
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe GettextI18nRails::ModelAttributesFinder do
|
13
|
+
let(:finder) { GettextI18nRails::ModelAttributesFinder.new }
|
14
|
+
|
15
|
+
before do
|
16
|
+
Rails.application
|
17
|
+
end
|
18
|
+
|
19
|
+
describe :find do
|
20
|
+
it "returns all AR models" do
|
21
|
+
keys = finder.find({}).keys
|
22
|
+
if Rails::VERSION::MAJOR > 2
|
23
|
+
keys.should == [CarSeat, NotConventional, Part]
|
24
|
+
else
|
25
|
+
keys.should == [CarSeat, Part]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns all columns for each model" do
|
30
|
+
attributes = finder.find({})
|
31
|
+
attributes[CarSeat].should == ['id', 'seat_color']
|
32
|
+
attributes[NotConventional].should == ['id', 'name'] if Rails::VERSION::MAJOR > 2
|
33
|
+
attributes[Part].should == ['car_seat_id', 'id', 'name']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -36,4 +36,40 @@ def with_file(content)
|
|
36
36
|
f.close
|
37
37
|
yield f.path
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
40
|
+
|
41
|
+
ActiveRecord::Base.establish_connection(
|
42
|
+
:adapter => "sqlite3",
|
43
|
+
:database => ":memory:"
|
44
|
+
)
|
45
|
+
|
46
|
+
ActiveRecord::Schema.define(:version => 1) do
|
47
|
+
create_table :car_seats, :force=>true do |t|
|
48
|
+
t.string :seat_color
|
49
|
+
end
|
50
|
+
|
51
|
+
create_table :parts, :force=>true do |t|
|
52
|
+
t.string :name
|
53
|
+
t.references :car_seat
|
54
|
+
end
|
55
|
+
|
56
|
+
create_table :not_at_all_conventionals, :force=>true do |t|
|
57
|
+
t.string :name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class CarSeat < ActiveRecord::Base
|
62
|
+
validates_presence_of :seat_color, :message=>"translate me"
|
63
|
+
has_many :parts
|
64
|
+
accepts_nested_attributes_for :parts
|
65
|
+
end
|
66
|
+
|
67
|
+
class Part < ActiveRecord::Base
|
68
|
+
belongs_to :car_seat
|
69
|
+
end
|
70
|
+
|
71
|
+
class NotConventional < ActiveRecord::Base
|
72
|
+
set_table_name :not_at_all_conventionals
|
73
|
+
end
|
74
|
+
|
75
|
+
ActiveRecord::Base.extend GettextI18nRails::ActiveRecord
|
metadata
CHANGED
@@ -1,42 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_i18n_rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Michael Grosser
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-05-19 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: fast_gettext
|
16
|
-
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
17
23
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
22
31
|
type: :runtime
|
32
|
+
requirement: *id001
|
23
33
|
prerelease: false
|
24
|
-
version_requirements: *13650380
|
25
34
|
description:
|
26
|
-
email:
|
35
|
+
email: michael@grosser.it
|
27
36
|
executables: []
|
37
|
+
|
28
38
|
extensions: []
|
39
|
+
|
29
40
|
extra_rdoc_files: []
|
30
|
-
|
41
|
+
|
42
|
+
files:
|
43
|
+
- .gitignore
|
31
44
|
- Gemfile
|
32
45
|
- Gemfile.lock
|
33
46
|
- Rakefile
|
34
47
|
- Readme.md
|
35
|
-
- VERSION
|
36
48
|
- gettext_i18n_rails.gemspec
|
37
49
|
- init.rb
|
38
50
|
- lib/gettext_i18n_rails.rb
|
39
51
|
- lib/gettext_i18n_rails/action_controller.rb
|
52
|
+
- lib/gettext_i18n_rails/active_model.rb
|
40
53
|
- lib/gettext_i18n_rails/active_record.rb
|
41
54
|
- lib/gettext_i18n_rails/backend.rb
|
42
55
|
- lib/gettext_i18n_rails/base_parser.rb
|
@@ -50,41 +63,51 @@ files:
|
|
50
63
|
- lib/gettext_i18n_rails/slim_parser.rb
|
51
64
|
- lib/gettext_i18n_rails/string_interpolate_fix.rb
|
52
65
|
- lib/gettext_i18n_rails/tasks.rb
|
66
|
+
- lib/gettext_i18n_rails/version.rb
|
53
67
|
- lib/tasks/gettext_rails_i18n.rake
|
54
68
|
- spec/gettext_i18n_rails/action_controller_spec.rb
|
69
|
+
- spec/gettext_i18n_rails/active_model_spec.rb
|
55
70
|
- spec/gettext_i18n_rails/active_record_spec.rb
|
56
71
|
- spec/gettext_i18n_rails/backend_spec.rb
|
57
72
|
- spec/gettext_i18n_rails/haml_parser_spec.rb
|
58
73
|
- spec/gettext_i18n_rails/hamlet_parser_spec.rb
|
74
|
+
- spec/gettext_i18n_rails/model_attributes_finder_spec.rb
|
59
75
|
- spec/gettext_i18n_rails/slim_parser_spec.rb
|
60
76
|
- spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
|
61
77
|
- spec/gettext_i18n_rails_spec.rb
|
62
78
|
- spec/spec_helper.rb
|
63
79
|
homepage: http://github.com/grosser/gettext_i18n_rails
|
64
|
-
licenses:
|
80
|
+
licenses:
|
81
|
+
- MIT
|
65
82
|
post_install_message:
|
66
83
|
rdoc_options: []
|
67
|
-
|
84
|
+
|
85
|
+
require_paths:
|
68
86
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
88
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
76
94
|
- 0
|
77
|
-
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
97
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
84
105
|
requirements: []
|
106
|
+
|
85
107
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.8.
|
108
|
+
rubygems_version: 1.8.24
|
87
109
|
signing_key:
|
88
110
|
specification_version: 3
|
89
111
|
summary: Simple FastGettext Rails integration.
|
90
112
|
test_files: []
|
113
|
+
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.4.6
|