Project

General

Profile

Actions

Internationalization

Tapestry uses the standard Rails Internationalization (I18N) API.

Not every page has been converted yet to use the I18N API. Patches are welcome. Translations to new languages are also welcome!

Setting the default locale for an installation

In the config/config.yml file, make sure to add the locale lines to the default section (or the section for your environment). For example, to add Dutch and make it the default locale:

  available_locales: [:en, :de, :nl]
  default_locale: :nl

Viewing a page in a different locale

You can pass the 'locale' URL query parameter to force a specific locale. Please note that the locale must be listed in the available_locales configuration variable.

Adding/editing translations

The locale files live under

  config/locales/defaults
  config/locales/views

View-specific locales should be defined under views. Please follow the established naming pattern for files and directories.

Using a custom folder location for translations

Somewhat similar to how overridden views can be placed in a folder on your system of your choosing (Customization), you can do this for translations as well. The default is #{Rails.root}/site_specific/config/locales but otherwise it will be the directory you specified as in Customization or #{ENV['TAPESTRY_OVERRIDE_PATH']}/config/locales.

Using translations in a view

Where possible, we use Lazy loading (see section 4.1.4).

For example, in

  app/views/users/index.html.erb

we write

  <h2><%= t('.participant_profiles') %></h2>

which maps to a yml file

config/locales/views/users/en.yml

with this structure

en:
  users:
    index:
      participant_profiles: "Participant Profiles" 

We could also write the lookup explicitly, like so:

  <h2><%= t('users.index.participant_profiles') %></h2

Updated by Phil Hodgson over 10 years ago · 2 revisions