Rails 2.2 was released late November, about two weeks ago. Of all the new features, one of the most prominent is the out-of-the-box implementation of internationalization (i18n, because it has 18 letters between I and N) in the new Rails 2.2 generated application (using the
rails
command).Before we dive into the implementation, we’re going to discuss a bit of the evolution of this solution.
In the Good Old Days (possibly before the Internet was widespread in usage), applications hard-coded their strings. So if you had a login form/box/control/screen/something, you’d have something like:
Login: <input type="text" />
Password: <input type="password" />
What, then, happens if you want to translate your application into another language like French? You could always hard-code the new values, and maintain a second version; but that’s expensive to maintain.
Then an idea emerged–how about storing the strings in a file somewhere, and using some sort of class to get the strings?
So you might have a class like this:
class LanguagePack
def get_string(string_key)
# open up a text file specified in LanguageManager.language
# look for the line with string_key
# return the actual text
end
end