Configuration
rails-i18n
provides several configuration options to tailor its behavior to your application's needs, helping to optimize performance and include only the features you require.
All configurations are set within your Rails application's configuration files, typically config/application.rb
or environment-specific files like config/environments/production.rb
.
Limiting Available Locales
By default, Rails loads all locale files found in the load path. Since rails-i18n
adds a large number of locales, this can add unnecessary memory overhead if your application only supports a few languages.
You can restrict which locales are loaded by setting config.i18n.available_locales
. The rails-i18n
gem will intelligently load only the data files (locales, pluralization, etc.) for the locales you specify.
Example: Load only German and Colombian Spanish
# config/application.rb
config.i18n.available_locales = [:de, 'es-CO']
Example: Load only Dutch
# config/application.rb
config.i18n.available_locales = :nl
If config.i18n.available_locales
is not set, the gem will load all available locale data.
Enabling and Disabling Modules
rails-i18n
is composed of four distinct modules. By default, all are enabled. You can choose to load only specific modules to further reduce the gem's footprint.
This is configured via config.rails_i18n.enabled_modules
.
The available modules are:
:locale
: The core translation files (.yml
).:pluralization
: Pluralization rules for different languages (.rb
).:ordinals
: Ordinalization rules (e.g., 1st, 2nd) for different languages (.rb
and.yml
).:transliteration
: Character transliteration rules (.rb
and.yml
).
Example: Enable only pluralization rules
This is useful if you manage your own locale files but need the complex pluralization logic provided by the gem.
# config/application.rb
config.rails_i18n.enabled_modules = [:pluralization]
Example: Enable pluralization and ordinals
# config/application.rb
config.rails_i18n.enabled_modules = [:pluralization, :ordinals]
If this configuration is left empty, all four modules will be loaded by default.