# Pagy::I18n


Use the i18n gem instead of the faster pagy-i18n implementation.

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

# Configuration

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

pagy.rb (initializer)
# 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| ... } })

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.

# Adding the model translations

If you use the pagy_info OR pagy_items_selector_js AND you also want to use the specific model names instead of the generic " items" string, THEN you may need to add entries for the models in the pagy dictionary files. For example:


  # added models strings
        one: Product
        other: Products

(See also the pagy_info method and How to customize the item name)

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