Project

General

Profile

Internationalization » History » Version 2

Phil Hodgson, 04/05/2014 05:32 PM

1 1 Ward Vandewege
h1. Internationalization
2
3
Tapestry uses the standard "Rails Internationalization (I18N) API":http://guides.rubyonrails.org/i18n.html.
4
5
Not every page has been converted yet to use the I18N API. Patches are welcome. Translations to new languages are also welcome!
6
7
h2. Setting the default locale for an installation
8
9
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:
10
11
<pre>
12
  available_locales: [:en, :de, :nl]
13
  default_locale: :nl
14
</pre>
15
16
h2. Viewing a page in a different locale
17
18
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.
19
20
h2. Adding/editing translations
21
22
The locale files live under
23
24
<pre>
25
  config/locales/defaults
26
  config/locales/views
27
</pre>
28
29
View-specific locales should be defined under views. Please follow the established naming pattern for files and directories.
30
31 2 Phil Hodgson
h3. Using a custom folder location for translations
32
33
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@.
34
35
36 1 Ward Vandewege
h2. Using translations in a view
37
38
Where possible, we use "Lazy loading":http://guides.rubyonrails.org/i18n.html#overview-of-the-i18n-api-features (see section 4.1.4). 
39
40
For example, in 
41
42
<pre>
43
  app/views/users/index.html.erb
44
</pre>
45
46
we write
47
48
<pre>
49
  <h2><%= t('.participant_profiles') %></h2>
50
</pre>
51
52
which maps to a yml file 
53
54
  config/locales/views/users/en.yml
55
56
with this structure
57
58
<pre>
59
en:
60
  users:
61
    index:
62
      participant_profiles: "Participant Profiles"
63
</pre>
64
65
We could also write the lookup explicitly, like so:
66
67
<pre>
68
  <h2><%= t('users.index.participant_profiles') %></h2
69
</pre>