Back to Pagy

I18n

docs/resources/i18n.md

43.5.33.5 KB
Original Source

:icon-globe:  Internationalization


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

!!!success Apps using only English language, are supported out of the box without any I18n Setup! !!!

=== :icon-list-ordered:  Setup

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.

Pick the I18n engine...

+++ Pagy::I18n

!!!success Recommended: ~18x faster and ~10x lighter It works seamlessly even if the rest of your app works with the i18n gem. !!!

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

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

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

+++ I18n gem

!!!warning Slower !!!

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

rb
Pagy.translate_with_the_slower_i18n_gem!

+++

==- :icon-book:  Sample Dictionary

:::code source="../gem/locales/en.yml" title="en.yml":::

==- :icon-pencil:  Customizing dictionaries

!!!warning IMPORTANT If you use Pagy::I18n, name your custom dictionary as <locale>.yml. !!!

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

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

==- :icon-mortar-board:  Contributing a Language

{{ include "snippets/ask-for-support" }}

Find the pluralization of your language...

{{ include "snippets/mini-step" step: "•1" }} Locate the file of your locale in the list of pluralizations

{{ include "snippets/mini-step" step: "•2" }} Check the pluralization used in it.

{{ include "snippets/mini-step" step: "•3" }} Confirm that Pagy has the same pluralization in the P18n directory.

||| If missing, you have two choices...

{{ include "snippets/mini-step" step: "easy" }} Create a new Feature Request asking for the addition of the pluralization for your locale.

{{ include "snippets/mini-step" step: "best" }} Create a new module for the pluralization (by adapting the same pluralization from the corresponding rails-i18n file) and include tests for it

|||

Duplicate an existing dictionary...

{{ include "snippets/mini-step" step: "•1" }} Pick a (similarly pluralized) dictionary in the lib/locales.

{{ include "snippets/mini-step" step: "•2" }} Set the p11n entry to the right pluralization module name in the P18n directory.

{{ include "snippets/mini-step" step: "•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.

==- :icon-location:  Localization

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

===