MailingList


Re: a proposed solution for localized templates

by Chris Cruft :: Rate this Message:

Reply to Author | View in Thread

Novik,
I was looking in this same area last week and I'm pretty sure I agree with you.  FWIW, I think the same thing can apply to ActionMailer.

Somebody needs to take the bull by the horns and wrest commit access from the existing core and fix this (and myriad other problems/opportunities) on Edge.

-Chris

On 2 May 2008, at 16:59, nnovik wrote:

Hi all, I've been poking at globalize with Rails Edge, and it's dying because of the Rails overhaul of ActionView and templates, but in a good cause. The following Rails 2.0 change:

multiple controller view paths

renders localized templates trivial to do. It seems to me the best solution at this point is to simply ditch lib/globalize/lib/rails/action_view.rb and just let users move this into the main application logic like so: (taken from a sample application.rb):
  before_filter :set_locale  
  # Determines the user's language of choice
  def set_locale
     
    (...typical code that among other things sets @locale to user's locale here...)
    
    # use the user's locale in their view path
    prepend_view_path File.join(File.dirname(__FILE__), '..', "views/localized/#{@locale}")
  end 

This particular solution will cause Rails to go look in views/localized/[locale]/ first and then fall back to the normal structure. So for instance, I have views/users/show.html.erb as the default, and then I have views/localized/fr/users/show.html.erb. When the viewer's locale is set to 'fr' the latter is the version that will appear.

This allows for individual-application control over how localized templates are managed, sequesters these templates nicely, and eliminates the need for globalize itself to be modified for future versions of Rails if future changes happen in this area.

Does anyone have thoughts on this? See a problem I've missed with this solution?

View this message in context: a proposed solution for localized templates
Sent from the Globalize-rails.org mailing list archive at Nabble.com.

 « Return to Thread: a proposed solution for localized templates