Home arrow Ruby-on-Rails arrow Page 2 - Multiple Language Support for an Ecommerce Application

Multiple Language Support for an Ecommerce Application

If you're building an ecommerce application that will do business in more than one country, you will probably need to support multiple languages. Indeed, you might face this problem even if you're doing business in just one state in the US, such as Florida or Texas. This four-part article series will show you how to add support for multiple languages to a Ruby-on-Rails ecomerce application. It is excerpted from chapter 10 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
June 25, 2010
  1. · Multiple Language Support for an Ecommerce Application
  2. · Using the Globalize Plugin
  3. · Localizing with Globalize
  4. · Localizing the Model

print this article

Multiple Language Support for an Ecommerce Application - Using the Globalize Plugin
(Page 2 of 4 )

Because of its close integration with Rails, the Globalize plugin provides a simple way of localizing the following in your application:

  1. Dates, times, numbers, and currencies. For example, 100000000.00 localized to US standards is 100,000,000.0. 
  2. Text stored in a database. For example, the book The Old Man and the Sea is Der alte Mann und das Meer in German. 
  3. Text used in views. For example, the link Next Page is Nästa Sida in Swedish.

But that’s not all. Currently, Globalize comes with built-in data for 7599 languages and 239 countries, including pluralization rules and language names. Globalize knows, for example, that Tuesday is tisdag in Swedish. Pluralization is done by specifying both the singular and plural form for a translation; for example, “Displaying one book” and “Displaying many books.”

Note  Globalize is not the only alternative for localizing Ruby on Rails applications. There’s also the GetText library, which allows you to externalize text into resource bundles and translate them into multiple languages. GetText doesn’t have as many features as Globalize and lacks support for things like date and currency formatting. For more information about GetText and other options, see http://wiki.rubyonrails.org/rails/pages/ InternationalizationComparison .

To install Globalize, execute the script/plugin script:

$ script/plugin install http://svn.globalize-rails.org/svn/globalize/globalize/trunk

The script checks out the latest version of the plugin from the Subversion repository and installs it in the vendor/plugins directory. By default, the directory is named trunk . You should give the directory a more descriptive name. For example, we renamed it to globalize-for-1.1 .

Note  At the time of writing, the latest version of Globalize didn’t support Rails 1.1. Instead of installing the latest version, we had to install the Rails 1.1 specific branch of Globalize with the following command: script/plugin install http://svn.globalize-rails.org/svn/globalize/globalize/ branches/for-1.1 .

Globalize extends the Rails framework’s ActionView, ActiveRecord, and ActionMailer modules, allowing it to provide the tools used for translating text. Globalize uses three database tables containing predefined data for thousands of languages and hundreds of countries:

  1. globalize_countries : Holds countries and the country-specific localization rules, including ISO 3166 country code, date formats, and currency formats. 
  2. globalize_languages : Holds languages and the language-specific localization rules, including ISO 639 language code, English name, and native name. 
  3. globalize_translations : Holds translated text. The table is prepopulated with data for hundreds of languages. The tr_key column contains text in the base language. The text column is where the actual translation is stored.

Figure 10-1. shows the schema for these tables.

Figure 10-1.  Globalize database schema

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials