#
Pagy::I18n
Pagy translates and pluralizes its strings using its own faster i18n implementation instead of depending on the slower i18n
gem.
The pagy_t translation
method is ~18x faster and uses ~10x less memory than the standard i18n
gem!
See i18n extra if you need to use the slower standard i18n
gem instead.
#
Dictionaries/locales
Pagy provides many ready-to-use dictionaries for different locales/languages usable with single or multi languages apps.
All the pagy strings are stored in the dictionary files of its locales,
ready to be customized and/or used with or without the I18n
gem. The files follow the same structure of the standard locale
files for the i18n
gem.
PRs Welcome!
If you are using pagy with some language missing from the locales, please, submit your translation!
#
Configuration
Configuration Not Required for: en
/ i18n extra
If your app uses only the default en
language or if you use the i18n extra you don't need to configure
anything for this module.
If you need to load different built-in locales, and/or custom dictionary files or even non built-in language and pluralization,
you can do it all by passing a few arguments to the Pagy::I18n.load
method.
#
Synopsis
# load the "de" built-in locale:
Pagy::I18n.load(locale: 'de')
# load the "de" locale defined in the custom file at :filepath:
Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml')
# load the "de", "en" and "es" built-in locales:
# the first :locale will be used also as the default locale
Pagy::I18n.load({ locale: 'de' },
{ locale: 'en' },
{ locale: 'es' })
# load the "en" built-in locale, a custom "es" locale, and a totally custom locale complete with the :pluralize proc:
Pagy::I18n.load({ locale: 'en' },
{ locale: 'es',
filepath: 'path/to/pagy-es.yml' },
{ locale: 'xyz', # not built-in
filepath: 'path/to/pagy-xyz.yml',
pluralize: lambda { |count| ... } })
Use one load statement
Use only one load statement or you will get a FrozenError exception
Customize only when required
You should use a custom :pluralize
proc only for pluralization types not included in the built-in pluralization rules (stored in
the Pagy::I18n::P11n::RULE
hash).
The :pluralize
proc should receive the count
as a single argument and should return the plural type string (e.g. something
like 'one'
or 'other'
, depending on the passed count).
#
Setting the request locale in multi-language apps
When you configure multiple locales (i.e. this does not apply to single locale apps), you must also set the locale at each
request. You usually do that in the application controller, by checking the :locale
param. For example, in a rails app you
should do something like:
before_action { @pagy_locale = params[:locale] }
If the @pagy_locale
is nil
or missing pagy will serve the first locale you set in the configuration.
#
Contribute a language
If you wish to add a new locale to pagy (see existing locales in the lib/locales directory) please follow the locales readme instructions here..