0

I have a ruby gem that I'm working on that includes some locale/I18n files that I would like to be loaded if and when the gem is used by Rails.

I've looked around a little and it looks like I need to provide a Railtie - I've found some examples here on stackoverflow and elsewhere, but I just can't get it to work.

Ideally, I would like this to work for Rails 3 and 4.

Here's the layout of my gem:

+ lib
    + my_gem
        my_gem.rb
        version.rb
+ locales
    en.yml

From what I've found it seems I need to add lib/my_gem/railtie.rb and put some code in there which appends the path to the .yml files in the locales directory of my gem. I've tried various different ways of doing this but I have been unable to get it to work.

1 Answers1

1

You should have this layout:

+ lib
    + my_gem
        engine.rb
        my_gem.rb
        version.rb
+ config
    + locales
        en.yml

In the engine.rb file you should extends Rails::Engine, like this:

module YourGem
   class Engine < Rails::Engine
   end
end

It should work! =)

Alexandre Bini
  • 127
  • 2
  • 12