Skip to content

Commit

Permalink
Dictionary structure changes:
Browse files Browse the repository at this point in the history
- The 'nav' entry has been flattened: 'pagy.nav.*' entries are now 'pagy.*'
- Added aria_label: group: removed *_label and change 'page' to 'nav'
  • Loading branch information
ddnexus committed Jan 31, 2024
1 parent 91decb3 commit 104536d
Show file tree
Hide file tree
Showing 67 changed files with 973 additions and 1,219 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ None
- Rack 3 breaking changes:
- The `headers` extra produces all lowercase headers, regardless how you set them [see rack issue](https://github.com/rack/rack/issues/1592)
- Removed `:escaped_html` option from `pagy_url_for` (only breaking if you override the method or use the option directly)

- Dictionary structure changes: (affects only app with custom helper/templates/dictionary entries)
- The `nav` entry has been flattened: `pagy.nav.*` entries are now `pagy.*`:
- If you have custom helpers/templates: search the keys that contain `'.nav.'` and replace them with `'.'`
- If you have custom dictionary entries (overrides): remove the `'nav:'` line and unindent its block.
- A few labels used as `aria-label` have been added: you may want to add them to your custom helper/templates/dictionaries for ARIA compliance.
- `aria_label.nav` Pluralized entry: used as the `aria-label` for the `nav` element
- `aria_label.prev`, `aria_label.next` Single entry: used in the prev/next `a` link elements

### Default changes (possibly breaking test/views)

- Changed `Pagy::DEFAULT[:size]` variable defaults from `[1, 4, 4, 1]` to `7`. You can explicitly set it in the initializer,
Expand All @@ -54,11 +61,12 @@ None
### Visual changes (possibly breaking test/views)

- The ARIA label compliance required the refactoring of all the nav helper that might look slightly different now.
- The text for `"Prev"` and `"Next"` is now used for the `aria-label` and has been replaced in the UI as `<` and `>`. You can
- The text for `"Previous"` and `"Next"` is now used for the `aria-label` and has been replaced in the UI as `<` and `>`. You can
edit the dictionary entries if you want to revert it to the previous default (`< Prev` and `Next >`)

### Changes

- Removed the pagy templates: they were a burden for maintenance with very limited usage
- Removed the pagy templates: they were a burden for maintenance with very limited usage.
- Internal renaming of private frontend methods

[LEGACY CHANGELOG >>>](CHANGELOG_LEGACY.md)
9 changes: 5 additions & 4 deletions docs/api/ARIA.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ The default string for the `aria-label` of the root element is "Page"/"Pages". I
Since the `nav` or `role="navigation"` elements of a HTML document are considered `landmark roles`, they should be uniquely aria-identified in the page. If you use more than one pagy helper in the same page, you should not rely on the default (that would otherwise generate a non-valid document), instead, you should pass either your own (possibly translated and pluralized) `aria-label` string or an i18n-key that locate the translated and pluralized string in your dictionary file. For example:

```erb
<%# Explicitly set the page_label string %>
<%== pagy_nav(@pagy, page_label: 'Search result pages') %>
<%# Explicitly set the nav_aria_label string %>
<%== pagy_nav(@pagy, nav_aria_label: 'Search result pages') %>
<%# I18n key in a dictionary file (pluralized entry) %>
<%== pagy_nav(@pagy, page_i18n_key: 'my.pagy_nav.aria_label') %>
<%# Pass an i18n key in a dictionary file (pluralized entry) %>
<%== pagy_nav(@pagy, nav_i18n_key: 'my.aria_label.nav') %>
```

## Links

- Links to the previous and next pages are rendered as "&lt;" and "&gt;" and are aria-labelled as translated `"Prev"` and `"Next"`.
Expand Down
7 changes: 5 additions & 2 deletions docs/api/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ The method accepts also a few optional keyword arguments variables:

- `:pagy_id`: the `id` HTML attribute to the `nav` tag (omitted by default)
- `:link_extra`: the verbatim string added to the `a` tag (e.g. `'data-remote="true"'`)
- `:page_label`: an already pluralized string for the `aria-label` attribute of the `nav`, that will be used in place of the default `nav.page_label`
- `:page_i18n_key`: the i18n dictionary key to lookup the default `pagy.page_label` pluralized value (ignored if `page_label` is defined)
- `:nav_aria_label`: an already pluralized string for the `aria-label` attribute of the `nav`, that will be used in place of
the default `pagy.aria_label.nav`
- `:nav_i18n_key`: the i18n dictionary key to lookup the default `pagy.aria_label.nav` pluralized value (ignored if
`nav_aria_label` is
defined)
- `:size` which use the passed size Array instead of the `:size` variable of the instance

See also [ARIA Attributes](ARIA.md).
Expand Down
57 changes: 22 additions & 35 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,23 @@ specific app.
# English default 118n dictionary
en:
pagy:

page_label:
one: "Page"
other: "Pages"

aria_label:
nav:
one: "Page"
other: "Pages"
previous: "Previous"
next: "Next"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"
item_name:
one: "item"
other: "items"

nav:
prev_label: "Prev"
next_label: "Next"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"

info:
no_items: "No %{item_name} found"
single_page: "Displaying <b>%{count}</b> %{item_name}"
multiple_pages: "Displaying %{item_name} <b>%{from}-%{to}</b> of <b>%{count}</b> in total"

combo_nav_js: "<label>Page %{page_input} of %{pages}</label>"

items_selector_js: "<label>Show %{items_input} %{item_name} per page</label>"
```
Expand Down Expand Up @@ -202,42 +196,35 @@ You may want to customize the output of a few entries, leaving the other entries
# English custom 118n dictionary
en:
pagy:

page_label:
one: "Page"
other: "Pages"

aria_label:
nav:
one: "Page"
other: "Pages"
previous: "Previous"
next: "Next"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"
item_name:
one: "item"
other: "items"

nav:
prev_label: "Prev"
next_label: "Next"
prev: "&lt;&nbsp;Prev" # customized
next: "Next&nbsp;&gt;" # customized
gap: "&hellip;"


info:
no_items: "0 of 0" # customized
single_page: "%{count} of %{count}" # customized
multiple_pages: "%{from}-%{to} of %{count}" # customized

combo_nav_js: "<label>Page %{page_input} of %{pages}</label>"

items_selector_js: "<label>Show %{items_input} %{item_name} per page</label>"
```
|||
## Customize the ARIA labels
You can customize the `aria-label` attributes of all the pagy helpers by passing either the `:page_label` or the
`:page_i18n_key` (See [pagy_nav](api/frontend.md#pagy-nav-pagy-vars))
You can customize the `aria-label` attributes of all the pagy helpers by passing either the `:nav_aria_label` string itself or
the `:nav_i18n_key` (See [pagy_nav](api/frontend.md#pagy-nav-pagy-vars))

You can also replace the `pagy.page_label` strings in the dictionary, as well as the `pagy.nav.prev_label` and the
`pagy.nav.next_label`.
You can also replace the `pagy.aria_label.nav` strings in the dictionary, as well as the `pagy.aria_label.previous` and the
`pagy.aria_label.next`.

See more details in the [ARIA attributes Page](api/ARIA.md).

Expand Down
14 changes: 7 additions & 7 deletions e2e/pagy_app.ru
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ __END__
<hr>

<p><%= "pagy_#{name_fragment}nav" %></p>
<%= send(:"pagy_#{name_fragment}nav", @pagy, pagy_id: 'nav', page_label: 'Pages nav') %>
<%= send(:"pagy_#{name_fragment}nav", @pagy, pagy_id: 'nav', nav_aria_label: 'Pages nav') %>
<hr>

<p><%= "pagy_#{name_fragment}nav_js" %></p>
<%= send(:"pagy_#{name_fragment}nav_js", @pagy, pagy_id: 'nav-js', page_label: 'Pages nav_js') %>
<%= send(:"pagy_#{name_fragment}nav_js", @pagy, pagy_id: 'nav-js', nav_aria_label: 'Pages nav_js') %>
<hr>

<p><%= "pagy_#{name_fragment}nav_js" %> (responsive)</p>
<%= send(:"pagy_#{name_fragment}nav_js", @pagy, pagy_id: 'nav-js-responsive',
page_label: 'Pages nav_js_responsive',
nav_aria_label: 'Pages nav_js_responsive',
steps: { 0 => [1,3,3,1], 600 => [2,4,4,2], 900 => [3,4,4,3] }) %>
<hr>

<p><%= "pagy_#{name_fragment}combo_nav_js" %></p>
<%= send(:"pagy_#{name_fragment}combo_nav_js", @pagy, pagy_id: 'combo-nav-js', page_label: 'Pages combo_nav_js') %>
<%= send(:"pagy_#{name_fragment}combo_nav_js", @pagy, pagy_id: 'combo-nav-js', nav_aria_label: 'Pages combo_nav_js') %>
<hr>


Expand All @@ -180,16 +180,16 @@ __END__

<p><%= "pagy_#{name_fragment}nav" %></p>
<%= send(:"pagy_#{name_fragment}nav", @calendar[:month], pagy_id: 'nav',
page_label: 'Pages nav') %>
nav_aria_label: 'Pages nav') %>
<hr>

<p><%= "pagy_#{name_fragment}nav_js" %></p>
<%= send(:"pagy_#{name_fragment}nav_js", @calendar[:month], pagy_id: 'nav-js',
page_label: 'Pages nav_js') %>
nav_aria_label: 'Pages nav_js') %>
<hr>

<p><%= "pagy_#{name_fragment}nav_js" %> (responsive)</p>
<%= send(:"pagy_#{name_fragment}nav_js", @calendar[:month], pagy_id: 'nav-js-responsive',
page_label: 'Pages combo_nav_js',
nav_aria_label: 'Pages combo_nav_js',
steps: { 0 => [1,3,3,1], 600 => [2,4,4,2], 900 => [3,4,4,3] }) %>
<hr>
35 changes: 14 additions & 21 deletions lib/locales/ar.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
# :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)

ar:
pagy:

# please add a comment in the https://github.com/ddnexus/pagy/issues/577
# posting the translation of page_label with the plurals for this locale
page_label: "Pages"
# zero: ""
# two: ""
# few: ""
# many: ""
# other: ""

aria_Label:
# please add a comment in the https://github.com/ddnexus/pagy/issues/577
# posting the translation of the following "Page"/"Pages" with the plurals for this locale
nav: "Pages"
# zero: ""
# two: ""
# few: ""
# many: ""
# other: ""
prev: "السابق"
next: "التالي"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"
item_name:
zero: "صفر"
one: "عنصر"
two: "عنصرين"
few: "قليل"
many: "كثير"
other: "عناصر"

nav:
prev_label: "السابق"
next_label: "التالي"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"

info:
no_items: "لا يوجد %{item_name}"
single_page: "عرض <b>%{count}</b> %{item_name}"
multiple_pages: "عرض %{item_name} <b>%{from}-%{to}</b> من اجمالي <b>%{count}</b>"

combo_nav_js: "الصفحة %{page_input} من %{pages}"

items_selector_js: "عرض %{items_input} %{item_name} لكل صفحة"
29 changes: 11 additions & 18 deletions lib/locales/be.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
# :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)

be:
pagy:

page_label:
one: "Старонка"
few: "Старонкi"
many: "Старонкi"
other: "Старонкi"

aria_label:
nav:
one: "Старонка"
few: "Старонкi"
many: "Старонкi"
other: "Старонкi"
prev: "Назад"
next: "Наперад"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"
item_name:
one: "запіс"
few: "запісы"
many: "запісаў"
other: "запісаў"

nav:
prev_label: "Назад"
next_label: "Наперад"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"

info:
no_items: "Пакуль %{item_name} няма"
single_page: "<b>%{count}</b> %{item_name}"
multiple_pages: "Усяго <b>%{count}</b> %{item_name}, паказаны з <b>%{from}</b> па <b>%{to}</b>"

combo_nav_js: "<label>Старонка %{page_input} з %{pages}</label>"

items_selector_js: "<label>Паказаць %{items_input} %{item_name} на старонцы</label>"
25 changes: 9 additions & 16 deletions lib/locales/bg.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
# :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)

bg:
pagy:

page_label:
one: "Страница"
other: "Страници"

aria_label:
nav:
one: "Страница"
other: "Страници"
prev: "Предишна"
next: "Следваща"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"
item_name:
one: "резултат"
other: "резултати"

nav:
prev_label: "Предишна"
next_label: "Следваща"
prev: "&lt;"
next: "&gt;"
gap: "&hellip;"

info:
no_items: "Няма намерени %{item_name}"
single_page: "Показани са <b>%{count}</b> %{item_name}"
multiple_pages: "Показани са %{item_name} <b>%{from}-%{to}</b> от <b>%{count}</b> общо"

combo_nav_js: "<label>Страница %{page_input} от %{pages}</label>"

items_selector_js: "<label>Покажи %{items_input} %{item_name} на страница</label>"
Loading

0 comments on commit 104536d

Please sign in to comment.