Spree Commerce

Try It Now

New on Edge Spree: Rails 2.2.2 & I18n

Posted on January 19, 2009 by Sean Schofield

Edge Spree has finally been updated to support Rails 2.2.2 including extensive use of Rails’ native I18n (internationalization) system which now replaces the Globalite plugin. The majority of the changes included in the 2.2.2 support are focused on leveraging I18n which now enables Spree to feature full ActiveRecord localization for model names, attributes and error / validation messages. The new Rails i18n is also significantly faster than the previous Globalite setup, so per session locale switching is now enabled by default.

Other important 2.2.2 related tweaks involving the updating of several core plugins including:

  • attribute-fu
  • has-many-polymorphs
  • rspec
  • rspec-rails
  • calendar-date-select

Overall the changes required to incorporate Rails 2.2.2 support are fairly extensive and have required updating every view, helper and layout within Spree, this will have a significant impact on existing customizations and extensions already in use, so we suggest you review these edge changes early before attempting to upgrade any production deployments (especially if you were using Globalite heavily).

Work is already underway to update the majority of active extensions to please check GitHub for the latest versions.

Notes for Extension Developers

Due to the removal of the Globalite plugin most extensions will have to be updated to support the new I18n features, the major areas that will need to be reviewed include:

1 Locale Files

The locale or translation yaml files have two important changes required:

1.1 New file locations

Using Globalite the locale yaml files where normally located under lang/ui/, under Rails 2.2.2 they should be relocated to: config/locales/

1.2 Translations must be nested under a language key

All locale files should be updated with a route key set to language code for that particular language, so the en-US.yml now looks like:

<p>en-US:<br />
  abbreviation: Abbreviation<br />
  access_denied: &#8220;Access Denied&#8221;<br />
  authorization_failure: &#8220;Authorization Failure&#8221;<br />
  account: Account<br />
  action: Action</p>

2 Translation helper method: t

Rails 2.2.2 continues to use the same t helper method for looking up translations as Globalite did, however there are a couple of minor differences:

2.1 The string parameter must be lower case:

<p>Rails 2.2.2:  t(&#8216;update&#8217;)<br />
Globalite:    t(&#8216;Update&#8217;)</p>

2.2 The string parameter should not contain white-space:

<p>Rails 2.2.2:  t(&#8216;shopping_cart&#8217;)<br />
Globalite:    t(&#8216;Shopping Cart&#8217;)</p>

For more on updating your extension take a look at the Flexi Rate Shipping extension which has been updated to support these new features.