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.

Localized templates does not work with "pt-BR" or "en-US" as locale

#1888

Localized templates is not working when the locale contains a dash "-" (for example index.pt-BR.html.erb and show.en-US.html.erb).

The reason of it is on rails/actionpack/lib/action_view/template.rb.

On line 239 we see the regexp that process our extensions in our view path is


    m = extensions.match(/^(\w+)?\.?(\w+)?\.?(\w+)?\.?/) 

The first parenthesis, which is the one that checks for the locale does not accepts dash -.

A working regexp would be:


  /^(\w+\-?\w*)?\.?(\w+)?\.?(\w+)?\.?/

And we can see it working on Rubular:

http://www.rubular.com/regexes/6077

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

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

Activity

  1. José Valim
    José Valim
    • Assigned user set to josh

    February 5th, 2009 @ 09:58 PM

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

    Just want to make sure, I18n supports dashed locales? If so, we should support this.

    Can you make a failing test case to go along with this and I'll get it in 2.3

    February 5th, 2009 @ 10:16 PM

  3. José Valim
    José Valim

    Yes, I18n supports dashed locales. Remember that at first, the default locale would even be "en-US"?

    I will make a failing test case and a patch. :)

    February 5th, 2009 @ 10:22 PM

  4. Sven Fuchs
    Sven Fuchs

    Yup, it does. Just for the record that's RFC4646 (http://tools.ietf.org/html/rfc46....1). Picked that one because it seemed like the best match.

    José, thanks for taking care of this!

    February 5th, 2009 @ 11:28 PM

  5. José Valim
    José Valim

    Patch attached!

    Josh, we are calling I18n.reload! to add locales in both rescue_test.rb and render_test.rb. This is not needed, because we are already adding the locales in abstract_unit.rb.

    I just didn't want to remove it, since it's not the scope of this patch, but I'm going to attach other soon.

    @Sven, glad to help! :)

    February 6th, 2009 @ 09:17 AM

  6. José Valim
    José Valim

    Josh, attached another patch "simplifying_rescue_tests.diff" and it should be applied after the first I sent.

    I removed such lines and everything still passes over here, but I would recommend you to check if it also passes on your machine.

    Regards!

    February 6th, 2009 @ 09:37 AM

  7. Repository
    Repository
    • State changed from open to resolved

    (from [24f2e676f700b8a387c6f4c27acf172658cd7863]) Added support to dashed locales in templates localization [#1888 Localized templates does not work with "pt-BR" or "en-US" as locale state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    February 7th, 2009 @ 05:29 AM