In this second part of a four-part article series on adding support for multiple languages to a Ruby-on-Rails ecomerce application, you will learn how to use Globalize to add this important capability. This article is excerpted from chapter 10 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Going Global with Multiple Language Support - Setting Up Globalize (Page 2 of 4 )
As previously mentioned, Globalize uses three database tables. After you’ve installed Globalize, as described earlier, run the following command to update your database schema and import the data:
$ rake globalize:setup
The command can take a minute or two to run, as it inserts a lot of data.
Next, you need to update the application’s environment configuration to include Globalize. This will initialize Globalize at startup. You should also set the base language and the default locale for your application in the same configuration file. To do all this, add the following code to the end of config/environment.rb :
# globalize include Globalize Locale.set_base_language 'en-US' DEFAULT_LOCALE = 'en-US'
The default locale is a separate setting, since it does not necessarily need to be the same as the base language. We are including Globalize in the default namespace with the include Globalize call, so that we can use Locale.set instead of Globalize::Locale.set .
Implementing the User Stories
With Globalize set up, we can now start localizing the Emporium application. But first, we’ll change the base controller so that users can change the locale.
Note We won’t be following TDD very strictly in this chapter, as we want to concentrate on showing you how to use the Globalize plugin.