gettext_i18n_rails 0.3.5 → 0.3.6

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gettext_i18n_rails}
8
- s.version = "0.3.5"
8
+ s.version = "0.3.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
@@ -22,6 +22,12 @@ require 'gettext_i18n_rails/backend'
22
22
  I18n.backend = GettextI18nRails::Backend.new
23
23
 
24
24
  require 'gettext_i18n_rails/i18n_hacks'
25
- require 'gettext_i18n_rails/active_record' if defined?(ActiveRecord)
25
+
26
+ require 'gettext_i18n_rails/active_record'
27
+ # If configuration via Railties is not available force activerecord extensions
28
+ if not defined?(Rails::Railtie) and defined?(ActiveRecord)
29
+ ActiveRecord::Base.extend GettextI18nRails::ActiveRecord
30
+ end
31
+
26
32
  require 'gettext_i18n_rails/action_controller' if defined?(ActionController) # so that bundle console can work in a rails project
27
33
  require 'gettext_i18n_rails/railtie'
@@ -1,21 +1,21 @@
1
- class ActiveRecord::Base
1
+ module GettextI18nRails::ActiveRecord
2
2
  # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
3
- def self.human_attribute_name(attribute, *args)
3
+ def human_attribute_name(attribute, *args)
4
4
  s_(gettext_translation_for_attribute_name(attribute))
5
5
  end
6
6
 
7
7
  # CarDealer -> _('car dealer')
8
- def self.human_name(*args)
8
+ def human_name(*args)
9
9
  _(self.human_name_without_translation)
10
10
  end
11
11
 
12
- def self.human_name_without_translation
12
+ def human_name_without_translation
13
13
  self.to_s.underscore.gsub('_',' ')
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def self.gettext_translation_for_attribute_name(attribute)
18
+ def gettext_translation_for_attribute_name(attribute)
19
19
  "#{self}|#{attribute.to_s.split('.').map! {|a| a.gsub('_',' ').capitalize }.join('|')}"
20
20
  end
21
21
  end
@@ -4,9 +4,19 @@ if defined?(Rails::Railtie)
4
4
  class Railtie < ::Rails::Railtie
5
5
  config.gettext_i18n_rails = ActiveSupport::OrderedOptions.new
6
6
  config.gettext_i18n_rails.msgmerge = %w[--sort-output --no-location --no-wrap]
7
+ config.gettext_i18n_rails.use_for_active_record_attributes = true
8
+
7
9
  rake_tasks do
8
10
  require 'gettext_i18n_rails/tasks'
9
11
  end
12
+
13
+ config.after_initialize do |app|
14
+ if app.config.gettext_i18n_rails.use_for_active_record_attributes
15
+ ActiveSupport.on_load :active_record do
16
+ extend GettextI18nRails::ActiveRecord
17
+ end
18
+ end
19
+ end
10
20
  end
11
21
  end
12
22
  end
@@ -19,6 +19,8 @@ ActiveRecord::Schema.define(:version => 1) do
19
19
  end
20
20
  end
21
21
 
22
+ ActiveRecord::Base.extend GettextI18nRails::ActiveRecord
23
+
22
24
  class CarSeat < ActiveRecord::Base
23
25
  validates_presence_of :seat_color, :message=>"translate me"
24
26
  has_many :parts
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext_i18n_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser