This project is archived and is in readonly mode.

#2785 ✓stale
John Smilanick

[PATCH] scoped translation throws an exception

Reported by John Smilanick | June 9th, 2009 @ 11:42 PM | in 3.x

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).

Comments and changes to this ticket

  • John Pignata

    John Pignata August 11th, 2009 @ 07:25 AM

    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?

  • John Pignata

    John Pignata August 11th, 2009 @ 07:30 AM

    • 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.

  • John Pignata

    John Pignata August 16th, 2009 @ 09:46 PM

    • 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.

  • John Pignata

    John Pignata August 17th, 2009 @ 04:20 AM

    • 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.

  • Martin Andert

    Martin Andert September 7th, 2009 @ 08:45 AM

    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.

  • Martin Andert

    Martin Andert January 15th, 2010 @ 12:41 PM

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

    Rizwan Reza February 12th, 2010 @ 12:46 PM

    • Tag changed from bugmash, i18n, rails3 to i18n, rails3
  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Rohit Arondekar

    Rohit Arondekar October 9th, 2010 @ 04:04 AM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages