Internationalization


Pagy handles string translation and pluralization using its own efficient i18n implementation.

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 engines.

Set the Pagy::I18n.locale for each request. For example:

Controller
before_action { Pagy::I18n.locale = params[:locale] }

Notice: The default Pagy::I18n.locale is 'en'.

Switch the translation to the i18n gem. Pagy will provide only its dictionaries...

Pagy.translate_with_the_slower_i18n_gem!
en.yml
# 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"

Place your custom dictionaries in a directory and add its path to the I18n pathnames.

# Example for Rails:
Pagy::I18n.pathnames << Rails.root.join('config/locales/pagy')

•1   Locate the file of your locale in the list of pluralizations

•2   Check the pluralization used in it.

•3   Confirm that Pagy has the same pluralization in the P18n directory.

If missing, you have two choices...

easy   Create a new Feature Request asking for the addition of the pluralization for your locale.

best   Create a new module for the pluralization (by adapting the same pluralization from the corresponding rails-i18n file) and include tests for it

•1   Pick a dictionary in the lib/locales.

•2   Set the p11n entry to the right pluralization module name in the P18n directory.

•3   Provide the necessary plurals for aria_label.nav and item_name.
E.g., with EastSlavic rule, provide the plurals for one, few, many, and other. With Other provide only the other value, etc.

Localization is needed only by the calendar with non en locales localization.