views:

786

answers:

4

I have a Rails 2.3.5 project that uses the localization features of Rails. I also happen to have Rails 3 beta installed (which depends on the i18n gem). Rails 2.3.5 will happily handle localization on it's own (without i18n installed), however if the i18n gem is available, it makes use of it.

Recently I upgraded my gems and now have version 0.3.7 and 0.4.0 of i18n installed. Rails, of course, wants to load and use the latest version which is causing errors in my project. I tried setting the gem version to 0.3.7 which gets around the errors in the web app. However, we're using resque and resque_mailer to delay the sending of messages. When the worker picks up the mailer job from the queue, it ignores my config.gem requirement in environment.rb and uses version 0.4.0 anyway.

Ideally, I'd like to tell Rails to just not use the i18n gem at all. How do I do that?

Update: As of beta 4, Rails 3 now requires i18n version 0.4.1. I don't see how more people aren't running into this problem as it would seem now if you have both Rails 2 and Rails 3 installed, you're going to run into this.

+3  A: 

You could use Bundler or RVM's Gemsets to make the i18n gem unavailable from within your app. Or you could upgrade your Rails app.

Konstantin Haase
While that's a valid answer, it's not the sort of answer I'm looking for. I am already using RVM, but many people aren't. There should be a way to handle this completely from within Rails if it's going to be a feature of Rails. You shouldn't have to install and set up RVM to manage a feature of Rails itself.
Jared
This is possible from "within" Rails 3 as it ships with Bundler. RubyGems has no option to disable a Gem completely. While you could explicitly activate an older version of i18n, the only way to get it out of your load path would be to not use rubygems at all.
Konstantin Haase
You can convert an older rails project to use gem bundler as well. Gem bundler has the ability to disable the system gems, relying on only the gems in the bundle.It also has far superior dependency management.Setup time: 15 minutes
Vertis
If you have further questions about RVM, there are people willing to help 24/7 in the #rvm channel on freenode: http://webchat.freenode.net/?channels=rvm.
Konstantin Haase
Well I've marked your answer as accepted, Konstantin. I've begrudgingly moved on to using gem sets to solve my problem. However, I still believe it's not the most ideal solution. There should be some facility in Rails to say "use this version of i18n" or to simply not use it at all even if it is available on the system.
Jared
+1  A: 

I followed instructions as defined here:

http://gembundler.com/rails23.html

and it worked.

Upvote for bundler. Since I've posted this, bundler has gone on to version 1.0 and become much better. It's very easy to set up in both Rails 2.3 and Rails 3 projects. It is the solution I'd use going forward.
Jared
A: 
  1. Freeze the rails version: rake VERSION=2.3.5 rails:freeze:gems
  2. Fix the version in the file vendor/rails/activesupport/lib/active_support/vendor.rb line 24 to: gem 'i18n', '>= 0.1.3', '< 0.4.0'
wingfire
A: 

Or just edit /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/vendor.rb and turn gem 'i18n', '>= 0.1.3' into gem 'i18n', '0.1.3

Paolo