This project is archived and is in readonly mode.

#4362 ✓committed
Craig Davey

[PATCH] Make translate less safe and more convenient

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

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.

Comments and changes to this ticket

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>

Attachments

Pages