nulogy-gettext_i18n_rails 0.4.6.2 → 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ .idea
2
+ pkg/*.gem
data/Gemfile CHANGED
@@ -1,16 +1,12 @@
1
1
  source :rubygems
2
+ gemspec
2
3
 
3
- gem 'fast_gettext'
4
-
5
- group :dev do
6
- gem 'haml'
7
- gem 'slim'
8
- gem 'hamlet'
9
- gem 'ruby_parser'
10
- gem 'gettext'
11
- gem 'sqlite3', '~>1.3.4'
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'
@@ -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
- begin
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = 'gettext_i18n_rails'
15
- gem.summary = "Simple FastGettext Rails integration."
16
- gem.email = "grosser.michael@gmail.com"
17
- gem.homepage = "http://github.com/grosser/#{gem.name}"
18
- gem.authors = ["Michael Grosser"]
19
- end
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
- Jeweler::GemcutterTasks.new
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/>
@@ -1,65 +1,13 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
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
- if s.respond_to? :specification_version then
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<fast_gettext>, [">= 0"])
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
-
@@ -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,7 @@
1
+ module ActiveModel
2
+ class Name < String
3
+ def human(options={})
4
+ _(@klass.humanize_class_name(self))
5
+ end
6
+ end
7
+ end
@@ -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.human_name_without_translation)
10
+ _(self.humanize_class_name(self.to_s))
10
11
  end
11
12
 
12
- def human_name_without_translation
13
- self.to_s.underscore.gsub('_',' ')
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
- "#{self}|#{attribute.to_s.split('.').map! {|a| a.humanize }.join('|')}"
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)
@@ -45,7 +48,7 @@ module GettextI18nRails
45
48
  end
46
49
 
47
50
  def models
48
- if Rails.respond_to?(:application)
51
+ if Rails::VERSION::MAJOR > 2
49
52
  Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
50
53
  ::ActiveRecord::Base.direct_descendants
51
54
  else
@@ -14,6 +14,7 @@ if defined?(Rails::Railtie)
14
14
  if app.config.gettext_i18n_rails.use_for_active_record_attributes
15
15
  ActiveSupport.on_load :active_record do
16
16
  extend GettextI18nRails::ActiveRecord
17
+ require 'gettext_i18n_rails/active_model.rb'
17
18
  end
18
19
  end
19
20
  end
@@ -79,7 +79,7 @@ namespace :gettext do
79
79
  ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
80
80
  GettextI18nRails.store_model_attributes(
81
81
  :to => storage_file,
82
- :ignore_columns => ['id', 'type', 'created_at', 'updated_at'],
82
+ :ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],
83
83
  :ignore_tables => ignore_tables
84
84
  )
85
85
  end
@@ -0,0 +1,3 @@
1
+ module GettextI18nRails
2
+ Version = VERSION = '0.5.0.1'
3
+ end
@@ -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('car seat').and_return('Autositz')
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
@@ -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,55 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nulogy-gettext_i18n_rails
3
- version: !ruby/object:Gem::Version
4
- hash: 115
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 6
10
- - 2
11
- version: 0.4.6.2
12
6
  platform: ruby
13
- authors:
7
+ authors:
14
8
  - Michael Grosser
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2012-04-05 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: fast_gettext
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
35
30
  description:
36
- email: grosser.michael@gmail.com
31
+ email: michael@grosser.it
37
32
  executables: []
38
-
39
33
  extensions: []
40
-
41
34
  extra_rdoc_files: []
42
-
43
- files:
35
+ files:
36
+ - .gitignore
44
37
  - Gemfile
45
38
  - Gemfile.lock
46
39
  - Rakefile
47
40
  - Readme.md
48
- - VERSION
49
41
  - gettext_i18n_rails.gemspec
50
42
  - init.rb
51
43
  - lib/gettext_i18n_rails.rb
52
44
  - lib/gettext_i18n_rails/action_controller.rb
45
+ - lib/gettext_i18n_rails/active_model.rb
53
46
  - lib/gettext_i18n_rails/active_record.rb
54
47
  - lib/gettext_i18n_rails/backend.rb
55
48
  - lib/gettext_i18n_rails/base_parser.rb
@@ -63,48 +56,42 @@ files:
63
56
  - lib/gettext_i18n_rails/slim_parser.rb
64
57
  - lib/gettext_i18n_rails/string_interpolate_fix.rb
65
58
  - lib/gettext_i18n_rails/tasks.rb
59
+ - lib/gettext_i18n_rails/version.rb
66
60
  - lib/tasks/gettext_rails_i18n.rake
67
61
  - spec/gettext_i18n_rails/action_controller_spec.rb
62
+ - spec/gettext_i18n_rails/active_model_spec.rb
68
63
  - spec/gettext_i18n_rails/active_record_spec.rb
69
64
  - spec/gettext_i18n_rails/backend_spec.rb
70
65
  - spec/gettext_i18n_rails/haml_parser_spec.rb
71
66
  - spec/gettext_i18n_rails/hamlet_parser_spec.rb
67
+ - spec/gettext_i18n_rails/model_attributes_finder_spec.rb
72
68
  - spec/gettext_i18n_rails/slim_parser_spec.rb
73
69
  - spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
74
70
  - spec/gettext_i18n_rails_spec.rb
75
71
  - spec/spec_helper.rb
76
72
  homepage: http://github.com/grosser/gettext_i18n_rails
77
- licenses: []
78
-
73
+ licenses:
74
+ - MIT
79
75
  post_install_message:
80
76
  rdoc_options: []
81
-
82
- require_paths:
77
+ require_paths:
83
78
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
85
80
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
86
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
102
91
  requirements: []
103
-
104
92
  rubyforge_project:
105
93
  rubygems_version: 1.8.21
106
94
  signing_key:
107
95
  specification_version: 3
108
96
  summary: Simple FastGettext Rails integration.
109
97
  test_files: []
110
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.6