Skip to content
Andreas Dausenau edited this page Jun 27, 2022 · 2 revisions

I18n

Ez-on-rails provides multilanguage support out of the box. Every generator you call that creates content takes care of creating files to provide translations.

The default locales are german (de) and english (en). The default locale is set to german, but you can change it in the config/initializers/i18n.rb file that was generated during the ezapp generator execution.

To add more languages you must do the following:

  1. Add the new locale in the locale scopes of the routes in the config/routes.rb file. Note that you must add this locale after each call of ezscaff
  2. Add the locale to the locale switch the _views/shared/locale_switch partial. You can eject the partial by calling ezviews. You can delete other ejected files you do not need.
  3. Provide the language files in the config/locales directory

The following section describes a helper that handles special cases of translations. This helper can be included in your controllers.

I18n Helper

Ez-on-rails provides the EzOnRails::EzI18nHelper to handle translations that rails may not provide. The following subsections describe the methods the helper provides.

human_enum_name(model_name, enum_name, value_key)

Translates the value of an enum. The enum values translations must be provided like this:

de:
  activerecord:
    enums:
      article:
        status:
          draft: Entwurf
          published: Veröffentlicht
          archived: Archiviert

This enables you to include the methods eg. in controllers and use the method like this:

human_enum_name(Article, 'status', @resource.status)
Clone this wiki locally