Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

page_entries_info customizable text #99

Closed
wants to merge 1 commit into from

6 participants

@alejopelaez

A simple change that allow the page_entires_info helper to receive more optional hash parameters used for customizing the helper output. This is especially useful when making web-pages in other languages.

@zealoushacker

+1

I think this is super important, because if we can't customize this text, we can't customize the ux appropriately. For example, let us say that instead of saying "No students found" in a student database, I had wanted to say: "Please add a student before viewing this table." This is currently impossible, without doing an if statement or something of the sort, and manually hacking in this message, and/or others like it.

mislav please merge this commit.

@davidgrieser

+1

Customizing text for helpers like this is crucial when working with designers. And legacy model systems.

@zoran

+1

@mislav mislav closed this pull request from a commit
@mislav have no fear, i18n is here!
:previous_label, :next_label, page gap text and the `page_entries_info`
method output can now all be translated by overriding values seen in
"lib/will_paginate/locale/en.yml" from your own application locale files.

closes #99, #10, #109
f1fba71
@mislav mislav closed this in f1fba71
@mislav
Owner

Sorry it took so long! Take a look at https://github.com/mislav/will_paginate/blob/rails3/lib/will_paginate/locale/en.yml

These are the values you can translate in your Rails 3 apps. Planning to backport this feature to older will_paginate so people on Rails 2 can use it, too.

@zealoushacker

mislav. Excellent. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2011
  1. @alejopelaez
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/will_paginate/view_helpers.rb
View
19 lib/will_paginate/view_helpers.rb
@@ -164,18 +164,29 @@ def paginated_section(*args, &block)
#
# <%= page_entries_info @posts, :entry_name => 'item' %>
# #-> Displaying items 6 - 10 of 26 in total
+ # Text is by default in english but can be changed by passing in the options
+ # hash the attributes :display_text, :found_text, :total_text, :all_text,
+ # :of_text, :in_text, :no_text, :one_text
def page_entries_info(collection, options = {})
entry_name = options[:entry_name] ||
(collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
+ display_text = options[:display_text] || "Displaying"
+ total_text = options[:total_text] || "total"
+ found_text = options[:found_text] || "found"
+ all_text = options[:all_text] || "all"
+ of_text = options[:of_text] || "of"
+ in_text = options[:in_text] || "in"
+ no_text = options[:no_text] || "No"
+ one_text = options[:one_text] || "1"
if collection.total_pages < 2
case collection.size
- when 0; "No #{entry_name.pluralize} found"
- when 1; "Displaying <b>1</b> #{entry_name}"
- else; "Displaying <b>all #{collection.size}</b> #{entry_name.pluralize}"
+ when 0; "#{no_text} #{entry_name.pluralize} #{found_text}"
+ when 1; "#{display_text} <b>#{one_text}</b> #{entry_name}"
+ else; "#{display_text} <b>#{all_text} #{collection.size}</b> #{entry_name.pluralize}"
end
else
- %{Displaying #{entry_name.pluralize} <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
+ %{#{display_text} #{entry_name.pluralize} <b>%d&nbsp;-&nbsp;%d</b> #{of_text} <b>%d</b> #{in_text} #{total_text}} % [
collection.offset + 1,
collection.offset + collection.length,
collection.total_entries
Something went wrong with that request. Please try again.