Skip to content

Commit

Permalink
cleanup of i81n plurals in code and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 29, 2018
1 parent 9de9268 commit 0422568
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
5 changes: 3 additions & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ These helpers take the Pagy object and returns the HTML string with the paginati
| Extra | Helpers |
| ---------------------------------- | ------------------------------------------------------ |
| [bootstrap](extras/bootstrap.md) | `pagy_nav_bootstrap` |
| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_responsive_bootstrap` |
| [compact](extras/compact.md) | `pagy_nav_compact`, `pagy_nav_compact_bootstrap` |
| [items](extras/items.md) | `pagy_items_selector` |
| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_responsive_bootstrap` |

Helpers are the preferred choice (over templates) for their performance. If you need to override a `pagy_nav*` helper you can copy and paste it in your helper end edit it there. It is a simple concatenation of strings with a very simple logic.

Expand All @@ -240,7 +241,7 @@ pagy = Pagy.new(count: 1000, link_extra: 'data-remote="true" class="my-class"')

## Customizing the params

You may need to massage the params embedded in the URLs of the page links. You can do so by redefining the `pagy_get_params` sub-method in your helper. It will receive the `params` hash complete with the `"page"` param and it should return a possibly modified version of it.
You may need to massage the params embedded in the URLs of the page links. You can do so by redefining the `pagy_get_params` sub-method in your helper. It will receive the `params` hash complete with the `:page` param and it should return a possibly modified version of it.

An example using `except` and `merge!`:

Expand Down
26 changes: 12 additions & 14 deletions lib/locales/plurals.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# This file adds support for multiple built-in plualization types.
# It defines the pluralization procs and gets eval(ed) at I18N.load time
# It defines the pluralization procs and gets eval(ed) at I18N.load time.
# frozen_string_literal: true

# utility variables
zero_one = ['zero', 'one']

# Rules
# A rule is a proc returning a plural type string based on the passed count
# Each plural rule may apply to many language/rule pairs below
rules = {
# Plurals
# A plural proc returns a plural type string based on the passed count
# Each plural proc may apply to one or more languages below
plurals = {
zero_one_other: -> (count) {zero_one[count] || 'other'}
}

# Plurals (language/rule pairs)
# The default rule for missing languages is the :zero_one_other rule (used for English)
plurals = Hash.new(rules[:zero_one_other])
# Languages (language/plural pairs)
# Contain all the entries for all the languages defined in the pagy.yml dictionary
# The default plural for missing languages is the :zero_one_other plural (used for English)
Hash.new(plurals[:zero_one_other]).tap do |languages|
languages['en'] = plurals[:zero_one_other]

# Entries for all the languages defined in the pagy.yml dictionary
plurals['en'] = rules[:zero_one_other]
# PR for other languages and plurals are very welcome. Thanks!

# PR for other languages are very welcome. Thanks!

# Return plurals
plurals
end

0 comments on commit 0422568

Please sign in to comment.