Created
June 10, 2011 22:15
-
-
Save dgilperez/1019899 to your computer and use it in GitHub Desktop.
monkey-patching will_paginate to support internationalization for page_entries_info using gettext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey-patching will_paginate to support internationalizated literals | |
module WillPaginate | |
module ViewHelpers | |
def page_entries_info(collection, options = {}) | |
entry_name = options[:entry_name] || | |
(collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' ')) | |
if collection.total_pages < 2 | |
case collection.size | |
when 0; _("No %{entries} found") % {:entries => entry_name.pluralize} | |
when 1; _("Displaying 1 %{entry}") % {:entry => entry_name} | |
else; _("Displaying all %{size} %{entries}") % {:size => collection.size, :entries => entry_name.pluralize} | |
end | |
else | |
_("Displaying %{entries} %{from} - %{to} of %{total} in total") % | |
{:from => collection.offset + 1, :to => collection.offset + collection.length, :total => collection.total_entries, :entries => entry_name.pluralize} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment