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.

[PATCH] Make translate less safe and more convenient

#4362

Currently, the translate helper marks all of it’s output as safe HTML.

This is a problem because storing translations as safely encoded HTML is a pain. And it becomes unsuitable if your translations are also used in non-HTML formats (such as plain text email). Most of the time translations are plain text so lets start treating them that way.

This patch changes the translate helper so that it doesn’t mark all translations as safe HTML. By default it leaves translations untouched so that encoding and safeness can be deferred to friends and helpers.

To handle the uncommon case where a translation includes HTML this patch also adds a naming convention for translation keys. When a key has the suffix "_html" or the last element of the key is the word "html" the translate helper will output a safe HTML string.

This naming convention helps to identify translations that include HTML tags so that you know what kind of output to expect when you call translate in a template.

Reported by Craig Davey · April 10th, 2010 @ 11:00 AM

State: committed
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Craig Davey
    Craig Davey
    • Tag set to actionpack, patch, translate

    April 10th, 2010 @ 11:02 AM

  2. DHH
    DHH
    • State changed from new to committed

    April 14th, 2010 @ 01:36 AM