Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgilperez/1019899 to your computer and use it in GitHub Desktop.
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
# 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