Module: WillPaginate::I18n
- Included in:
- LinkRenderer, PageEntriesInfoRenderer
- Defined in:
- lib/will_paginate/i18n.rb
Overview
Contains all of the internationalization (i18n) information that WillPaginate::LinkRender uses.
Each of several strings can be customized. Each string has a default value that can be overridden on a site-wide or page-specific basis. (NB: page-specific translations won’t work for inline templates; only for the more typical views.)
Previous
-
Default: “« Previous” (an HTML left-angle-quote and ‘Previous’)
-
Site-wide key: “will_paginate.previous_label”
-
Page-specific key: “#controller.#view.will_paginate.previous_label”
Next
-
Default: “Next »” (‘Next’ and an HTML right-angle-quote)
-
Site-wide key: “will_paginate.next_label”
-
Page-specific key: “#controller.#view.will_paginate.next_label”
Gap Marker
-
Default: “<span class=”gap“>…</span>” (an HTML ellipsis wrapped in a span)
-
Site-wide key: “will_paginate.gap_marker”
-
Page-specific key: “#controller.#view.will_paginate.gap_marker”
Entry Name
Used when the type of paginated object cannot be otherwise determined.
-
Default: “entry”
-
Site-wide key: “will_paginate.entry_name”
-
Page-specific key: “#controller.#view.will_paginate.entry_name”
Page entries info (zero elements)
-
Default: “No {pluralized_entry_name} found”
-
Site-wide key: “will_paginate.page_entries_info.zero”
-
Page-specific key: “#controller.#view.will_paginate.page_entries_info.zero”
-
Interpolation options: “pluralized_entry_name”
# ==== Page entries info (one element)
-
Default: “Displaying 1 {entry_name}”
-
Site-wide key: “will_paginate.page_entries_info.one”
-
Page-specific key: “#controller.#view.will_paginate.page_entries_info.one”
-
Interpolation options: “entry_name”
# ==== Page entries info (one page of elements)
-
Default: “Displaying all #total_count {pluralized_entry_name}”
-
Site-wide key: “will_paginate.page_entries_info.all”
-
Page-specific key: “#controller.#view.will_paginate.page_entries_info.all”
-
Interpolation options: “pluralized_entry_name”, “total_count”
# ==== Page entries info (n-m of x elements)
-
Default: “Displaying {pluralized_entry_name} {start_count} - {end_count} of {total_count} in total”
-
Site-wide key: “will_paginate.page_entries_info.n_to_m_of_x”
-
Page-specific key: “#controller.#view.will_paginate.page_entries_info.n_to_m_of_x”
-
Interpolation options: “pluralized_entry_name”, “start_count”, “end_count”, “total_count”
Example: set some site-wide values and page-specific overrides for blog posts:
# in RAILS_ROOT/config/locales/en.yml:
en:
will_paginate:
previous_label: "<-- Previous"
next_label: "Next -->"
gap_marker: " - "
page_entries_info:
one: "One {{entry_name}} found:"
all: "All {{pluralized_entry_name}}:"
n_to_m_of_x: "{{pluralized_entry_name}} {{start_count}} to {{end_count}} of {{total_count}}:"
posts:
index:
will_paginate:
previous_label: "<-- Earlier"
next_label: "Later -->"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.append_translations_load_path ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/will_paginate/i18n.rb', line 75 def self.append_translations_load_path locales_dir = File.(File.join(File.dirname(__FILE__), '..', '..', 'locales')) Dir.glob("#{locales_dir}/**/*.{rb,yml}").each do |path| unless ::I18n.load_path.include?(path) ::I18n.load_path << path end end end |
Instance Method Details
#gap_marker ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/will_paginate/i18n.rb', line 105 def gap_marker if @gap_marker WillPaginate::Deprecation::warn("WillPaginate::LinkRenderer#gap_marker is deprecated; please see WillPaginate::I18n.", caller) @gap_marker else translate :gap_marker end end |
#next_label ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/will_paginate/i18n.rb', line 96 def next_label if [:next_label] WillPaginate::Deprecation::warn(":next_label view parameter is deprecated; please see WillPaginate::I18n.", caller) [:next_label] else translate :next_label end end |
#page_entries_info ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/will_paginate/i18n.rb', line 114 def page_entries_info entry_name, pluralized_entry_name = entry_name_and_pluralized_for_collection interpolations = { :entry_name => entry_name, :pluralized_entry_name => pluralized_entry_name, :total_count => collection.size } if self.collection.total_pages < 2 case collection.size when 0; key = 'page_entries_info.zero' when 1; key = 'page_entries_info.one' else; key = 'page_entries_info.all' end else key = 'page_entries_info.n_to_m_of_x' interpolations.merge!({ :start_count => self.collection.offset + 1, :end_count => self.collection.offset + self.collection.length, :total_count => self.collection.total_entries }) end translate key, interpolations end |
#previous_label ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/will_paginate/i18n.rb', line 84 def previous_label if [:prev_label] WillPaginate::Deprecation::warn(":prev_label view parameter is deprecated; please see WillPaginate::I18n.", caller) [:prev_label] elsif [:previous_label] WillPaginate::Deprecation::warn(":previous_label view parameter is deprecated; please see WillPaginate::I18n.", caller) [:previous_label] else translate :previous_label end end |