-
Notifications
You must be signed in to change notification settings - Fork 4
Internationalization
Internationalization refers to translation of text elements as well as localization of numeric, date and time formats.
Text elements in views should never be hardcoded in one language. Instead, use the Rails Internationalization (I18n) API so the text is displayed in the correct language according to the user's preference.
Before: <h1>Job Offers</h1>
After: <h1><%= t("job_offers.headline") %></h1>
The correct translations for the text element need to be supplied. In this case, they should be added to the following two files: config/locales/views/job_offers/en.yml
and config/locales/views/job_offers/en.yml
.
Follow the following structure:
en:
job_offers:
headline: "Job Offers"
de:
job_offers:
headline: "Stellenangebote"
For each model a de.yml
and en.yml
file must be created in config/locales/models/, where is the name of the model in singular form. The files should contain all the model attributes with their corresponding translations.
Before: <%= label_tag :chair %>
After : <%= label_tag t("activerecord.attributes.job_offer.chair") %>
The two files in the /config/locales/defaults
folder supply translations for simple element names like "Edit", "New", etc.
If a date is displayed, it is possible to internationalize the format of the date by doing this:
Before: <%= job_offer.start_date %>
After : <%= l(job_offer.start_date) %>