-
Notifications
You must be signed in to change notification settings - Fork 147
Translating templates
Each subdirectory of app
gets its own de.xxx.yml
file in config/locales/de
(please see existing files for a starting point). All German strings need to be changed, e.g. in the file app/views/home/_start_nav.haml
%h3 Direkt zu ...
was changed to
%h3= t '.title'
The =
lets the remainder of the line be parsed as code. The t()
function takes care of translation, and it argument '.title'
is an identifier. Since it starts with a .
, Ruby on Rails prepends view directory and simplified filename in addition to the locale, so that the full identifier becomes de.home.start_nav
. This is put into config/locales/de/de.home.yml.
When there is a more complex command on the line, the function call needs to have brackets. E.g.
%li= link_to "Mitglieder", foodcoop_users_path
was changed to
%li= link_to t('.members'), foodcoop_users_path
The brackets are required so that the parser knows that foodcoop_users_path
belongs to link_to()
(and not to t()
).
Another issue is when code appears in the text. To separate code from text, it is better to put that in an argument than inside the translation. For example
%small (Letzte Aktualisierung ist #{distance_of_time_in_words(Time.now, current_user.ordergroup.account_updated)} her)
was changed to
%small= t '.my_ordergroup.last_update', when: distance_of_time_in_words(Time.now, current_user.ordergroup.account_updated)
The corresponding text in in the locale file was set to Letzte Aktualisiering ist %{when} her
. Note the use of the percent sign to reference the variable given on the t()
command.
I hope this is enough to get you going! And please feel free to expand this.