I18n support for plugins/gems?

What does everybody think about this ticket?

https://rails.lighthouseapp.com/projects/8994/tickets/2325-i18n-support-for-engines

Basically the question is: Should Rails as a framework automatically try to load any translations supplied by plugins and/or gems? Or should the developer be responsible for adding these manually?

I personally tend to solutions that give the developer more control by just requiring himself to do the right thing. I can see though that - as Rails loads the application's translations automatically - one would want the plugin translations to be loaded as well.

Any opinions?

With engines being able to add functionality, I believe that this functionality will also need to be translated and it should be the responsibility of those providing the functionality, not the developer of the application.

Sure :slight_smile:

The question remains … should an Engine dev be expected add something like this to their code?

init.rb

I18n.load_path += Dir[‘/path/to/translations/**/*.{yml,rb}’]

Or should Rails do that automagically for everybody’s plugins/gems?

In my opinion yes. Why not load automagically the translations path when Rails is doing so with the routes.

With this what we achieve is that all engines will have the same structure, so it will be easier for people to know where to look for the translation files.

In the case of the engine I've been working on, I store the translations using the same structure Rails does.

    vendor/plugins/typus/lib/locales/typus/es.yml

At this moment, without supporting it, the developer has to manage what to do when the engine is a gem.

    if plugin?       I18n.load_path += Dir[File.join(root, 'config', 'locales', '**', '*.{rb,yml}')]     else       Gem.path.each { |g| I18n.load_path += Dir[File.join("#{g}/gems/ *typus-#{version}/config/locales/**/*.{rb,yml}")] }     end

Agree with Francesc

What does everybody think about this ticket?

#2325 i18n support for Engines - Ruby on Rails - rails

Basically the question is: Should Rails as a framework automatically try to load any translations supplied by plugins and/or gems?

Yes, I think it should

I personally tend to solutions that give the developer more control by just requiring himself to do the right thing.

Sure, but I'm not sure what the benefit would be in this case; and they could always put the in a non standard place and load them manually if they really want to

Automagically, with the file kept in the I18n.load_path (inside the engine)

Alright, that’s a clear vote of 4:0 :slight_smile:

I’ll have a look at a patch. I assume this can go into 2.3.x?

I'll have a look at a patch. I assume this can go into 2.3.x?

Let's start with master and look at backporting if it's simple and 'purely additive'.

I guess it is :slight_smile:

Here are two patches for master and 2-3-stable:

https://rails.lighthouseapp.com/projects/8994/tickets/2325/a/256496/0001_master_i18n-load_path-support-for-engines.patch https://rails.lighthouseapp.com/projects/8994/tickets/2325/a/256522/0001_2-3-stable_i18n-load_path-support-for-engines.patch

Ticket:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2325-i18n-support-for-engines

Thanks Sven for pushing this.

I'm afraid it was incomplete. Engine translations are added at the end of the I18n.load_path, so they take precedence over application translations.

I think application developers should be able to overwrite engine translations, so here is a patch for it:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3537- prioritize-application-i18n-above-engine-i18n

http://github.com/atd/rails/commit/6161e719012e856a59248fe338ff1c014ed344b3