Translatable strings

For i18n, strings such as replies, help messages, and user-oriented error messages should be translated into the user's language.

Marking strings as translatable

In the source code, translatable strings generally need to be marked with the _ method, for example, _('This message should be translated'). There is also an n_ method designed for messages with singular and plural forms.

Strings with embedded code

Unfortunately ruby-gettext cannot work strings like "The sum of #{a} and #{b} is #{a + b}". You'll need to rewrite translatable strings into this form:

_("The sum of %{a} and %{b} is %{sum}") % {:a => a, :b => b, :sum => a + b}

Note that ruby-gettext extends String#% to make it take a hash argument. This makes it easier for translators to understand the strings, and to translate them into languages that may have different word order patterns from English.

Avoid string concatenation

Using string concatenation, for example

str = "The file is"
str << " not " unless found?
str << "found."
str

can make messages difficult to translate into other languages. Always try to write whole messages as strings, like

if found? 
  _("The file is found.")
else
  _("The file is not found.")
end

Follow GNU Gettext Manual's tips on preparing strings.