-
Notifications
You must be signed in to change notification settings - Fork 1
Localization using I18n
There is currently support for the following languages:
- English
en
- German
de
The localization files for each language are stored under config/locales
as a YAML file named after the language code (i.e. de.yml
for German, en.yml
for English). The YAML files contain key-value pairs denoting a translation key and a string containing the actual translation. For example:
en:
hello: 'Hello world'
people: 'People'
title-en: 'English'
title-de: 'German'
All keys should be defined for all available languages. The YAML files can be organized to use specific scopes as shown in the I18n Guide or several YAML files can be used with a corresponding folder structure, see Guide
We are using the I18n gem for server side localization.
See here for a guide on how to add translations to your code.
To translate a string use the t
helper method in place of the string:
<h1><%= t('hello') %></h1>
The key ('hello') must be defined in the localization files.
You can get the current locale via I18n.locale
.
In the frontend we are using the i18njs and/or i18n library.
To translate a string, use the I18n.t
method in the JavaScript code in place of a string:
I18n.t('hello')
The key ('hello') must be defined in the localization files.
You can get the current locale via I18n.locale
.
The current locale (en
or de
) is saved in the url query via the locale
parameter. By default the english locale is used.
All relative links should preserve this locale when using the link_to
rails helper to create links.
The locale can be added to the end of the url by hand to apply the corresponding locale.