| 
1 | 1 | module ActiveAdmin  | 
2 | 2 |   class Resource < Config  | 
3 | 3 |     module Naming  | 
4 |  | -      # An underscored safe representation internally for this resource  | 
5 |  | -      def underscored_resource_name  | 
6 |  | -        @underscored_resource_name ||= if @options[:as]  | 
7 |  | -          @options[:as].gsub(' ', '').underscore.singularize  | 
8 |  | -        else  | 
9 |  | -          resource.name.gsub('::','').underscore  | 
10 |  | -        end  | 
11 |  | -      end  | 
12 |  | - | 
13 | 4 |       # Returns the name to call this resource.  | 
14 |  | -      # By default will use resource.model_name.human  | 
15 | 5 |       def resource_name  | 
16 |  | -        @resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)  | 
17 |  | -          underscored_resource_name.titleize  | 
18 |  | -        else  | 
19 |  | -          resource.model_name.human.titleize  | 
20 |  | -        end  | 
 | 6 | +        @resource_name ||= @options[:as]  | 
 | 7 | +        @resource_name ||= singular_human_name  | 
 | 8 | +        @resource_name ||= resource.name.gsub('::',' ')  | 
21 | 9 |       end  | 
22 | 10 | 
 
  | 
23 | 11 |       # Returns the plural version of this resource  | 
24 | 12 |       def plural_resource_name  | 
25 |  | -        @plural_resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)  | 
26 |  | -          resource_name.pluralize  | 
27 |  | -        else  | 
28 |  | -          # Check if we have a translation available otherwise pluralize  | 
29 |  | -          begin  | 
30 |  | -            I18n.translate!("activerecord.models.#{resource.model_name.underscore}")  | 
31 |  | -            resource.model_name.human(:count => 3)  | 
32 |  | -          rescue I18n::MissingTranslationData  | 
33 |  | -            resource_name.pluralize  | 
34 |  | -          end  | 
 | 13 | +        @plural_resource_name ||= @options[:as].pluralize if @options[:as]  | 
 | 14 | +        @plural_resource_name ||= plural_human_name  | 
 | 15 | +        @plural_resource_name ||= resource_name.pluralize  | 
 | 16 | +      end  | 
 | 17 | + | 
 | 18 | +      private  | 
 | 19 | + | 
 | 20 | +      # @return [String] Human name via ActiveRecord I18n or nil  | 
 | 21 | +      def singular_human_name  | 
 | 22 | +        return nil unless resource.respond_to?(:model_name)  | 
 | 23 | +        resource.model_name.human  | 
 | 24 | +      end  | 
 | 25 | + | 
 | 26 | +      # @return [String] Plural human name via ActiveRecord I18n or nil  | 
 | 27 | +      def plural_human_name  | 
 | 28 | +        return nil unless resource.respond_to?(:model_name)  | 
 | 29 | +        begin  | 
 | 30 | +          I18n.translate!("activerecord.models.#{resource.model_name.i18n_key}")  | 
 | 31 | +          resource.model_name.human(:count => 3)  | 
 | 32 | +        rescue I18n::MissingTranslationData  | 
 | 33 | +          nil  | 
35 | 34 |         end  | 
36 | 35 |       end  | 
37 | 36 |     end  | 
 | 
0 commit comments