I18n support for plugins/gems?

78 views
Skip to first unread message

Sven Fuchs

unread,
Aug 26, 2009, 7:23:23 AM8/26/09
to rubyonra...@googlegroups.com
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?

Ryan Bigg (Radar)

unread,
Aug 26, 2009, 7:28:02 AM8/26/09
to rubyonra...@googlegroups.com
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.

2009/8/26 Sven Fuchs <sven...@artweb-design.de>



--
Ryan Bigg

Sven Fuchs

unread,
Aug 26, 2009, 7:38:10 AM8/26/09
to rubyonra...@googlegroups.com
Sure :)

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?

Francesc Esplugas

unread,
Aug 26, 2009, 7:52:05 AM8/26/09
to Ruby on Rails: Core

On Aug 26, 1:38 pm, Sven Fuchs <svenfu...@artweb-design.de> wrote:

> 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}']

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

Luca Guidi

unread,
Aug 26, 2009, 8:32:53 AM8/26/09
to rubyonra...@googlegroups.com
Agree with Francesc

Mateo Murphy

unread,
Aug 26, 2009, 10:50:18 AM8/26/09
to rubyonra...@googlegroups.com

On 26-Aug-09, at 7:23 AM, Sven Fuchs wrote:

>
> 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?

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


Ryan Bigg (Radar)

unread,
Aug 26, 2009, 4:23:21 PM8/26/09
to rubyonra...@googlegroups.com


2009/8/26 Sven Fuchs <sven...@artweb-design.de>

Sure :)

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?

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

Sven Fuchs

unread,
Aug 30, 2009, 8:12:50 AM8/30/09
to rubyonra...@googlegroups.com
Alright, that's a clear vote of 4:0 :)

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

Michael Koziarski

unread,
Aug 30, 2009, 2:00:55 PM8/30/09
to rubyonra...@googlegroups.com
> 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'.

--
Cheers

Koz

Sven Fuchs

unread,
Aug 30, 2009, 2:24:16 PM8/30/09
to rubyonra...@googlegroups.com

Antonio Tapiador del Dujo

unread,
Dec 2, 2009, 10:04:11 AM12/2/09
to rubyonra...@googlegroups.com, Sven Fuchs
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
Reply all
Reply to author
Forward
0 new messages