Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

HTML fallback when format is :js should be also localized

#1886

The current implementation of localized templates on rails/actionpack/lib/action_view/paths.rb is incomplete.

At line 48, in the method find_template, when we check for a html file if the format is js, we should try first to find the localized version of this file. So what we have now as:


  # Try to find html version if the format is javascript
  elsif format == :js && template = load_path["#{template_path}.html"]
    return template
  end

Should actually be:


  # Try to find html version if the format is javascript
  elsif format == :js && template = load_path["#{template_path}.#{I18n.locale}.html"]
    return template
  elsif format == :js && template = load_path["#{template_path}.html"]
    return template
  end

I'm not building a patch, since it's a quick fix.

Reported by José Valim · February 5th, 2009 @ 06:00 PM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. José Valim
    José Valim

    Trying again:

    The current implementation of localized templates on rails/actionpack/lib/action_view/paths.rb is incomplete.

    At the line 48, when we check for a html file when format is js (this is used in when xhr? is true) should be also localized. So what we have now as:

    
      # Try to find html version if the format is javascript
      elsif format == :js && template = load_path["#{template_path}.html"]
        return template
      end
    

    Should actually be:

    
      # Try to find html version if the format is javascript
      elsif format == :js && template = load_path["#{template_path}.#{I18n.locale}.html"]
        return template
      end
      elsif format == :js && template = load_path["#{template_path}.html"]
        return template
      end
    

    I'm not building a patch, since it's a quick fix.

    February 5th, 2009 @ 06:01 PM

  2. josh
    josh
    • State changed from new to incomplete

    Can you please add some unit tests.

    February 5th, 2009 @ 09:36 PM

  3. José Valim
    José Valim

    Joshua, patch attached.

    I could not see tests for HTML fallback even when not localized. So I added tests for both cases.

    February 6th, 2009 @ 09:20 AM

  4. José Valim
    José Valim

    Joshua,

    Don't forget to add this one. The tests provide a failing scenario.

    Thanks!

    February 7th, 2009 @ 07:58 AM

  5. josh
    josh
    • State changed from incomplete to open
    • Milestone cleared.

    February 7th, 2009 @ 04:56 PM

  6. Repository
    Repository
    • State changed from open to resolved

    (from [50f51ff95047858fa6dd889ade3027b7254c6dc0]) Render implicit html template when xhr request now supports localization [#1886 HTML fallback when format is :js should be also localized state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    February 7th, 2009 @ 06:08 PM