Skip to content

Commit

Permalink
rescuing I18n::MissingTranslationData is slower than adding a default…
Browse files Browse the repository at this point in the history
… to the I18n.t call
  • Loading branch information
James McKinney committed Jul 6, 2012
1 parent ffef502 commit 84afa0c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
6 changes: 1 addition & 5 deletions lib/active_admin/sidebar_section.rb
Expand Up @@ -25,11 +25,7 @@ def icon

# The title gets displayed within the section in the view
def title
begin
I18n.t!("active_admin.sidebars.#{name.to_s}")
rescue I18n::MissingTranslationData
name.to_s.titlecase
end
I18n.t("active_admin.sidebars.#{name.to_s}", :default => name.to_s.titlecase)
end

# If a block is not passed in, the name of the partial to render
Expand Down
11 changes: 4 additions & 7 deletions lib/active_admin/view_helpers/breadcrumb_helper.rb
Expand Up @@ -9,7 +9,7 @@ def breadcrumb_links(path = nil)
parts.pop unless %w{ create update }.include?(params[:action])
crumbs = []
parts.each_with_index do |part, index|
name = ""
name = nil
if part =~ /^\d|^[a-f0-9]{24}$/ && parent = parts[index - 1]
begin
parent_class = parent.singularize.camelcase.constantize
Expand All @@ -19,12 +19,9 @@ def breadcrumb_links(path = nil)
end
end

name = part.titlecase if name == ""
begin
crumbs << link_to( I18n.translate!("activerecord.models.#{part.singularize}", :count => 1.1), "/" + parts[0..index].join('/'))
rescue I18n::MissingTranslationData
crumbs << link_to( name, "/" + parts[0..index].join('/'))
end
name ||= I18n.t("activerecord.models.#{part.singularize}", :count => 1.1, :default => part.titlecase)

crumbs << link_to( name, "/" + parts[0..index].join('/'))
end
crumbs
end
Expand Down
11 changes: 3 additions & 8 deletions lib/active_admin/views/components/paginated_collection.rb
Expand Up @@ -89,19 +89,14 @@ def build_download_format_links(formats = [:csv, :xml, :json])
def page_entries_info(options = {})
if options[:entry_name]
entry_name = options[:entry_name]
entries_name = options[:entries_name]
entries_name = options[:entries_name] || entry_name.pluralize
elsif collection.empty?
entry_name = I18n.translate("active_admin.pagination.entry", :count => 1, :default => 'entry')
entries_name = I18n.translate("active_admin.pagination.entry", :count => 2, :default => 'entries')
else
begin
entry_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1)
entries_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size)
rescue I18n::MissingTranslationData
entry_name = collection.first.class.name.underscore.sub('_', ' ')
end
entry_name = I18n.translate("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1, :default => collection.first.class.name.underscore.sub('_', ' '))
entries_name = I18n.translate("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size, :default => entry_name.pluralize)
end
entries_name = entry_name.pluralize unless entries_name

if collection.num_pages < 2
case collection.size
Expand Down
6 changes: 1 addition & 5 deletions lib/active_admin/views/components/scopes.rb
Expand Up @@ -28,11 +28,7 @@ def build(scopes, options = {})

def build_scope(scope, options)
li :class => classes_for_scope(scope) do
begin
scope_name = I18n.t!("active_admin.scopes.#{scope.id}")
rescue I18n::MissingTranslationData
scope_name = scope.name
end
scope_name = I18n.t("active_admin.scopes.#{scope.id}", :default => scope.name)

a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
text_node scope_name
Expand Down
6 changes: 1 addition & 5 deletions lib/active_admin/views/dashboard_section_renderer.rb
Expand Up @@ -11,11 +11,7 @@ def build(section)
protected

def title
begin
I18n.t!("active_admin.sections.#{@section.name.to_s}")
rescue I18n::MissingTranslationData
@section.name.to_s.titleize
end
I18n.t("active_admin.sections.#{@section.name.to_s}", :default => @section.name.to_s.titleize)
end

end
Expand Down

0 comments on commit 84afa0c

Please sign in to comment.