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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

[PATCH] scoped translation throws an exception

#2785

If I have a view that is localized, (eg. home#index.zh.html) and I still have a t() helper then in fails to translate relative keys.

Example:
t('.header') => "zh, home, index, zh, header"
instead of
t('.header') => "ZH Header"

It looks like it is including the 'zh' when figuring out the path therefore it fails to find the translation. The method 'path_without_format_and_extension' seems to return the locale so maybe it should use a new method that doesn't include the locale (eg. path_without_format_and_extension_and_locale).

Reported by John Smilanick · June 9th, 2009 @ 11:42 PM

State: stale
Milestone: 3.x
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: none

Activity

  1. John Pignata
    John Pignata

    This is really broken in Rails 3 due to the Action View refactoring. The test continues to pass because of a stub but when trying to use scoped keys, a call to the removed path_without_format_and_extension causes an error.

    I guess we'll have to patch the translation helper to do its own parsing of template.identifier to support scoped keys in the 3. Any thoughts?

    August 11th, 2009 @ 07:25 AM

  2. John Pignata
    John Pignata
    • Tag changed from i18n to i18n, rails3
    • Title changed from translation helper fails in localized views to scoped translation throws an exception

    To clarify the above - this is verified in 2-3-stable, and even worse in master as translation_helper hasn't been refactored to be in step with the new Action View code.

    August 11th, 2009 @ 07:30 AM

  3. John Pignata
    John Pignata
    • Assigned user set to Yehuda Katz (wycats)

    Here's my attempt at a fix. I've added the details previously accessible in path_without_format_and_extension by the translation helper to the new details hash.

    August 16th, 2009 @ 09:46 PM

  4. John Pignata
    John Pignata
    • Title changed from scoped translation throws an exception to [PATCH] scoped translation throws an exception

    Here's a patch to fix the more minor problem of scoped translations not working in localized views on 2.3.3.

    August 17th, 2009 @ 04:20 AM

  5. Martin Andert
    Martin Andert

    The patch for rails3 doesn't apply (anymore). The template Variable seems to be always nil. As a fix for this I changed a line in action_view/render/rendering.rb:

        def render_template(options)
          _evaluate_assigns_and_ivars
          #template, layout, partial = options.values_at(:_template, :_layout, :_partial)
          self.template, layout, partial = options.values_at(:_template, :_layout, :_partial)
          _render_template(template, layout, options, partial)
        end
    

    But then the scope_key_by_partial method in translation_helper.rb returns a localization key with double periods ("..") in it.

    September 7th, 2009 @ 08:45 AM

  6. Martin Andert
    Martin Andert
    • Tag changed from i18n, rails3 to bugmash, i18n, rails3

    January 15th, 2010 @ 12:41 PM

  7. Rizwan Reza
    Rizwan Reza
    • Tag changed from bugmash, i18n, rails3 to i18n, rails3

    February 12th, 2010 @ 12:46 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  9. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:04 AM