Internationalization » History » Version 1
Ward Vandewege, 01/28/2014 04:04 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 | h2. Using translations in a view |
||
32 | |||
33 | Where possible, we use "Lazy loading":http://guides.rubyonrails.org/i18n.html#overview-of-the-i18n-api-features (see section 4.1.4). |
||
34 | |||
35 | For example, in |
||
36 | |||
37 | <pre> |
||
38 | app/views/users/index.html.erb |
||
39 | </pre> |
||
40 | |||
41 | we write |
||
42 | |||
43 | <pre> |
||
44 | <h2><%= t('.participant_profiles') %></h2> |
||
45 | </pre> |
||
46 | |||
47 | which maps to a yml file |
||
48 | |||
49 | config/locales/views/users/en.yml |
||
50 | |||
51 | with this structure |
||
52 | |||
53 | <pre> |
||
54 | en: |
||
55 | users: |
||
56 | index: |
||
57 | participant_profiles: "Participant Profiles" |
||
58 | </pre> |
||
59 | |||
60 | We could also write the lookup explicitly, like so: |
||
61 | |||
62 | <pre> |
||
63 | <h2><%= t('users.index.participant_profiles') %></h2 |
||
64 | </pre> |