Skip to content

Localization instructions

Pekka Ekman edited this page Mar 26, 2012 · 8 revisions

Translation files

All translation files are located under config/locales/. There are three kinds of localization systems in use: Gettext, Rails I18n and localized partials.

All translation files are encoded as UTF-8.

Gettext

Gettext translations are in the gettext subdirectory. They contain translations for strings marked translatable with _() in source code. The application uses the fast_gettext gem for displaying the translated strings.

Gettext files can be edited either with a text editor or with a specialized po-file editor. If editing with a text editor, msgid is the original English string and msgstr is the translation. Untranslated strings have an empty string in msgstr; fast_gettext will display the original English strings for these. Some original strings start with a namespace string and the separator character | (namespace_string|The actual text). The namespace and the | character must not be included in the translated string.

Rails I18n

Rails I18n files are in files <locale_id>.yml directly in the locales directory. They contain translations for strings not under application developer's control that come from Rails internal or plugin code, such as model attribute names (used in forms and form error messages).

Rails I18n files are YAML files that contain a hierarchical structure of keys and associated translated strings. The language name shown in locale selector is under the key <locale_id>.i18n.language.name.

Localized partials

Longer texts are in their own partials under the partials subdirectory. Partials are Ruby on Rails' template files that contain a part of a page's content. The directory structure is the same as in app/views/. The files have the language code as a part of their file name, e.g. _longtext.en.html.erb.

The files with .erb extension may contain ruby code inside <% %> or <%= %> delimiters. Ruby code can be used for inserting values of variables or setting variables related to the partial, such the subject of an e-mail. Files that are rendered to web pages (i.e. everything except e-mail partials) may also contain HTML tags, which means that the characters < and & must be encoded as HTML entities (&lt;, &amp;).

Updating Gettext files

When new translatable strings are added or existing ones changed, the Gettext files should be updated with the following command:

rake gettext:find

In order for this to work, Gettext binaries must be installed. In Ubuntu (and probably Debian) this can be done with the command apt-get install gettext.