From 8fedb4f77d76d047833dce82c0f6919f0f9a7a79 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Lopes Ribeiro Date: Tue, 21 Feb 2012 20:10:34 -0200 Subject: [PATCH] Adding i18n to page_entries_info fixes #208 --- config/locales/kaminari.yml | 9 +++++++++ lib/kaminari/helpers/action_view_extension.rb | 16 ++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config/locales/kaminari.yml b/config/locales/kaminari.yml index eb3ec65..ce90ec3 100644 --- a/config/locales/kaminari.yml +++ b/config/locales/kaminari.yml @@ -8,3 +8,12 @@ en: previous: "‹ Prev" next: "Next ›" truncate: "..." + helpers: + page_entries_info: + one_page: + display_entries: + zero: "No %{entry_name} found" + one: "Displaying 1 %{entry_name}" + other: "Displaying all %{count} %{entry_name}" + more_pages: + display_entries: "Displaying %{entry_name} %{first} - %{last} of %{total} in total" diff --git a/lib/kaminari/helpers/action_view_extension.rb b/lib/kaminari/helpers/action_view_extension.rb index 5fd753d..7955098 100644 --- a/lib/kaminari/helpers/action_view_extension.rb +++ b/lib/kaminari/helpers/action_view_extension.rb @@ -94,20 +94,16 @@ module Kaminari entry_name = entry_name.underscore.sub('_', ' ') end entry_name = options[:entry_name] unless options[:entry_name].nil? + entry_name = entry_name.pluralize unless collection.total_count == 1 output = "" if collection.num_pages < 2 - output = case collection.total_count - when 0; "No #{entry_name.pluralize} found" - when 1; "Displaying 1 #{entry_name}" - else; "Displaying all #{collection.total_count} #{entry_name.pluralize}" - end + output = t("helpers.page_entries_info.one_page.display_entries", { :count => collection.total_count, :entry_name => entry_name }) else offset = (collection.current_page - 1) * collection.limit_value - output = %{Displaying #{entry_name.pluralize} %d - %d of %d in total} % [ - offset + 1, - offset + collection.current_page_count, - collection.total_count - ] + output = t("helpers.page_entries_info.more_pages.display_entries", { :entry_name => entry_name, + :first => offset + 1, + :last => offset + collection.current_page_count, + :total => collection.total_count }) end output.html_safe end