Skip to content

Commit 84afa0c

Browse files
author
James McKinney
committed
rescuing I18n::MissingTranslationData is slower than adding a default to the I18n.t call
1 parent ffef502 commit 84afa0c

File tree

5 files changed

+10
-30
lines changed

5 files changed

+10
-30
lines changed

lib/active_admin/sidebar_section.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ def icon
2525

2626
# The title gets displayed within the section in the view
2727
def title
28-
begin
29-
I18n.t!("active_admin.sidebars.#{name.to_s}")
30-
rescue I18n::MissingTranslationData
31-
name.to_s.titlecase
32-
end
28+
I18n.t("active_admin.sidebars.#{name.to_s}", :default => name.to_s.titlecase)
3329
end
3430

3531
# If a block is not passed in, the name of the partial to render

lib/active_admin/view_helpers/breadcrumb_helper.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def breadcrumb_links(path = nil)
99
parts.pop unless %w{ create update }.include?(params[:action])
1010
crumbs = []
1111
parts.each_with_index do |part, index|
12-
name = ""
12+
name = nil
1313
if part =~ /^\d|^[a-f0-9]{24}$/ && parent = parts[index - 1]
1414
begin
1515
parent_class = parent.singularize.camelcase.constantize
@@ -19,12 +19,9 @@ def breadcrumb_links(path = nil)
1919
end
2020
end
2121

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

lib/active_admin/views/components/paginated_collection.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,14 @@ def build_download_format_links(formats = [:csv, :xml, :json])
8989
def page_entries_info(options = {})
9090
if options[:entry_name]
9191
entry_name = options[:entry_name]
92-
entries_name = options[:entries_name]
92+
entries_name = options[:entries_name] || entry_name.pluralize
9393
elsif collection.empty?
9494
entry_name = I18n.translate("active_admin.pagination.entry", :count => 1, :default => 'entry')
9595
entries_name = I18n.translate("active_admin.pagination.entry", :count => 2, :default => 'entries')
9696
else
97-
begin
98-
entry_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1)
99-
entries_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size)
100-
rescue I18n::MissingTranslationData
101-
entry_name = collection.first.class.name.underscore.sub('_', ' ')
102-
end
97+
entry_name = I18n.translate("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1, :default => collection.first.class.name.underscore.sub('_', ' '))
98+
entries_name = I18n.translate("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size, :default => entry_name.pluralize)
10399
end
104-
entries_name = entry_name.pluralize unless entries_name
105100

106101
if collection.num_pages < 2
107102
case collection.size

lib/active_admin/views/components/scopes.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ def build(scopes, options = {})
2828

2929
def build_scope(scope, options)
3030
li :class => classes_for_scope(scope) do
31-
begin
32-
scope_name = I18n.t!("active_admin.scopes.#{scope.id}")
33-
rescue I18n::MissingTranslationData
34-
scope_name = scope.name
35-
end
31+
scope_name = I18n.t("active_admin.scopes.#{scope.id}", :default => scope.name)
3632

3733
a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
3834
text_node scope_name

lib/active_admin/views/dashboard_section_renderer.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ def build(section)
1111
protected
1212

1313
def title
14-
begin
15-
I18n.t!("active_admin.sections.#{@section.name.to_s}")
16-
rescue I18n::MissingTranslationData
17-
@section.name.to_s.titleize
18-
end
14+
I18n.t("active_admin.sections.#{@section.name.to_s}", :default => @section.name.to_s.titleize)
1915
end
2016

2117
end

0 commit comments

Comments
 (0)