Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on May 22, 2012
@sskirby sskirby makes humanization work with ActiveModel entities that include Active…
…Model::Translation
ab72646
Commits on May 24, 2012
@grosser Merge pull request #68 from nulogy/add_humanization_to_active_model
makes humanization work with ActiveModels
47dc988
View
21 lib/gettext_i18n_rails/active_model.rb
@@ -4,4 +4,25 @@ def human(options={})
_(@klass.humanize_class_name)
end
end
+
+ module Translation
+ # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
+ def human_attribute_name(attribute, *args)
+ s_(gettext_translation_for_attribute_name(attribute))
+ end
+
+ def gettext_translation_for_attribute_name(attribute)
+ attribute = attribute.to_s
+ if attribute.ends_with?('_id')
+ humanize_class_name(attribute)
+ else
+ "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
+ end
+ end
+
+ def humanize_class_name(name=nil)
+ name ||= self.to_s
+ name.underscore.humanize
+ end
+ end
end
View
19 lib/gettext_i18n_rails/active_record.rb
@@ -1,25 +1,8 @@
module GettextI18nRails::ActiveRecord
- # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
- def human_attribute_name(attribute, *args)
- s_(gettext_translation_for_attribute_name(attribute))
- end
+ include ActiveModel::Translation
# method deprecated in Rails 3.1
def human_name(*args)
_(self.humanize_class_name)
end
-
- def humanize_class_name(name=nil)
- name ||= self.to_s
- name.underscore.humanize
- end
-
- def gettext_translation_for_attribute_name(attribute)
- attribute = attribute.to_s
- if attribute.ends_with?('_id')
- humanize_class_name(attribute)
- else
- "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
- end
- end
end
View
1 lib/gettext_i18n_rails/railtie.rb
@@ -13,7 +13,6 @@ class Railtie < ::Rails::Railtie
config.after_initialize do |app|
if app.config.gettext_i18n_rails.use_for_active_record_attributes
ActiveSupport.on_load :active_record do
- extend GettextI18nRails::ActiveRecord
require 'gettext_i18n_rails/active_model.rb'
end
end

No commit comments for this range

Something went wrong with that request. Please try again.