#
#
Internationalization
Pagy handles string translation and pluralization using its own efficient i18n implementation.
Pagy::I18n.translate
is approximately 18 times faster and consumes about 10 times less memory compared to the standard I18n.translate
provided by the i18n
gem!
All Pagy strings are stored in dictionary files within its locales.
These files adopt the same structure as the standard locale files for the i18n
gem, allowing you to use them seamlessly with both
systems.
# See https://ddnexus.github.io/pagy/resources/i18n
en:
pagy:
p11n: 'OneOther'
aria_label:
nav:
one: "Page"
other: "Pages"
previous: "Previous"
next: "Next"
previous: "<"
next: ">"
gap: "…"
item_name:
one: "item"
other: "items"
info_tag:
no_count: "Page %{page} of %{pages}"
no_items: "No %{item_name} found"
single_page: "Displaying %{count} %{item_name}"
multiple_pages: "Displaying %{item_name} %{from}-%{to} of %{count} in total"
input_nav_js: "Page %{page_input} of %{pages}"
limit_tag_js: "Show %{limit_input} %{item_name} per page"
Simply place your customized dictionary files in a directory and add its path to the I18n pathnames. Uncomment or modify the relevant line in the pagy.rb initializer.
# Example for Rails:
Pagy::I18n.pathnames << Rails.root.join('config/locales')
The default Pagy::I18n.locale
is 'en'
.
For applications with multiple locales, you must set the Pagy::I18n.locale
for each request. For instance, in a Rails application, you can implement this as follows:
before_action { Pagy::I18n.locale = params[:locale] }
Prefer Pagy::I18n
Pagy::I18n functions seamlessly and independently of the i18n
gem, offering significantly better performance.
If you absolutely need to use the i18n
gem for translating Pagy, you can simply uncomment the following line in your pagy.js initializer:
Pagy.translate_with_the_slower_i18n_gem!
Once enabled, you will no longer need to configure Pagy::I18n.locale
, as the global I18n.locale
will automatically handle it.