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.

Wrong Content-Type when using localized templates

#1850

Hi,

when I use localized template like : index.fr.html.erb, the Content-Type header sent by the server becomes "fr.html; charset=utf-8" instead of the standard "text/html; charset=utf-8".

Because of this problem, my browser (Firefox 3) sets a bad character decoder (ISO instead of UTF-8) and my views are broken.

Reported by Nicolas Blanco · February 2nd, 2009 @ 10:20 PM

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

Activity

  1. Nicolas Blanco
    Nicolas Blanco
    • Tag set to 2.3, i18n, localization, templates

    OK.

    More information : the bad Content-Type is only sent when the locale is not properly loaded/valid (for example in a new Rails application, you set the locale to :fr in the environment.rb file but you don't put a fr.yml file).

    But IMHO, the Content-Type sent by Rails should be valid even if the locale is not valid/loaded.

    February 3rd, 2009 @ 10:07 AM

  2. josh
    josh
    • State changed from new to wontfix
    • Milestone cleared.

    You can register more extensions without adding more configs to locales with

    
    I18n.backend.store_translations 'fr', {}
    

    February 3rd, 2009 @ 11:24 PM

  3. hkstar
    hkstar

    Strongly disagree with above "wontfix". The current behaviour is to half-work, with an incorrect content-type, causing insidious and confusing hard-to-troubleshoot errors. I spent a couple of hours tracking this nasty bug down before finally arriving here.

    The "fix" is undocumented and obscure. The localised templates otherwise work, just silently include a completely wrong content-type. What excuse is there for that kind of hideous bug?

    This ticket needs to be re-opened immediately.

    February 17th, 2009 @ 11:58 AM

  4. Eloy Duran
    Eloy Duran

    Hmm, we had this issue too, but while I was investigating the issue it was fixed, for at least our case, in edge by another commit.

    @hkstar: I would suggest you write some failing unit tests for Template#split, which is most probably where the problem lies.

    February 17th, 2009 @ 12:30 PM

  5. Robert Glaser
    Robert Glaser

    Strongly disagree with "wontfix", too!

    March 24th, 2009 @ 11:26 AM

  6. Steven Bedrick
    Steven Bedrick

    I also disagree with the "wontfix"- I've just run into this bug, and I most definitely have my locale loaded and set correctly. Other parts of the Rails I18n system are working fine, strings are being loaded from my locale file on other templates, etc... but anything that tries to load a localized view displays the above-described behavior. The correct (i.e., localized) view loads, is rendered, and is then sent down to the browser with a content-type of "#{locale}.html".

    August 28th, 2009 @ 01:43 AM

  7. Kris Leech
    Kris Leech

    This also happens if you use a template filename such as edit.default.html.erb, the content-type in this case is set to edit.html, not text/html.

    Changing to edit_default.html.erb or manually setting the correct content-type header prevents this problem but imposes a naming scheme on your templates or additional work.

    Rails 2.3.5

    February 18th, 2010 @ 12:05 PM

  8. Michael Reinsch
    Michael Reinsch
    • Importance changed from to

    With rails 2.3.8, I don't seem to be able to fix this issue with the workaround given.

    As far as I can tell, the I18n backend is correctly initialized (dumping it indeed shows that :ja has translations). But still, the content type for a "support.ja.html.haml" template is set to "ja.html; charset=utf-8".

    July 14th, 2010 @ 03:02 AM

  9. James Le Cuirot
    James Le Cuirot

    It works for me with a more recent 2-3-stable but my workaround is to actually create empty locale files like this.

    ja:
      activerecord:
    

    July 14th, 2010 @ 08:46 AM