# HTML character codes in ActionMailer subject

**URL:** <https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257>\
**Category:** Rails\
**Created:** [May 27, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257 "2010-05-27T16:29:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 27, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/1 "2010-05-27T16:29:31Z")

</div>

Hi,

We have our e-mail subjects stored in I18n locale files. For the  
English version of the website, we had no problem, but now we’re  
translating to German, which uses a lot of symbols like ü and  
Ü for example. We store them as character codes in the YAML  
files, but most e-mail clients won’t parse HTML-code in the subjects.  
Is it fine to just use the actual characters in the YAML files? Will  
that work on any system?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 27, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/2 "2010-05-27T18:25:22Z")

</div>

Jaap H. wrote:

> Hi,
> 
> We have our e-mail subjects stored in I18n locale files. For the  
> English version of the website, we had no problem, but now we’re  
> translating to German, which uses a lot of symbols like ü and  
> Ü for example. We store them as character codes in the YAML  
> files,

Why? That’s a really bad idea.

> but most e-mail clients won’t parse HTML-code in the subjects.  
> Is it fine to just use the actual characters in the YAML files?

Yes.

> Will  
> that work on any system?

Yes, provided you specify the correct encoding (I recommend UTF-8 for  
everything).

> Thanks in advance!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 28, 2010, 7:36am UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/3 "2010-05-28T07:36:20Z")

</div>

> > We have our e-mail subjects stored in I18n locale files. For the  
> > English version of the website, we had no problem, but now we’re  
> > translating to German, which uses a lot of symbols like ü and  
> > Ü for example. We store them as character codes in the YAML  
> > files,
> 
> Why? That’s a really bad idea.

Because the subject lines are used in our website as well. xHTML  
strict needs our “strange” characters to be character codes.

> everything).  
> Thanks. Is there a way to convert these HTML character codes to the  
> actual characters?

Jaap

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 28, 2010, 7:50pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/4 "2010-05-28T19:50:10Z")

</div>

Hassan S. wrote:

> On Thu, May 27, 2010 at 10:35 PM, jhaagmans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > > We have our e-mail subjects stored in I18n locale files. For the  
> > > > English version of the website, we had no problem, but now we’re  
> > > > translating to German, which uses a lot of symbols like ü and  
> > > > Ü for example. We store them as character codes in the YAML  
> > > > files,
> 
> > Because the subject lines are used in our website as well. xHTML  
> > strict needs our “strange” characters to be character codes.
> 
> ? What makes you think that? Or to put it another way: no, it doesn’t  
> 🙂

Right. In both HTML 4 and XHTML, any Unicode character is valid.

But even if that weren’t so, you should be storing the actual “strange”  
characters and escaping them on output. And you’ve just discovered why.

> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 28, 2010, 8:46pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/5 "2010-05-28T20:46:36Z")

</div>

Let me put in another way: we have multiple people updating the  
language strings in the YAML files. For people working on OS X, the  
characters will show up as squares on Linux and vice versa. I only  
control one of these systems. How would you approach this? Our  
approach has worked for some time now this way and we only have  
problems with ActionMailer subjects.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 28, 2010, 5:24pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/6 "2010-05-28T17:24:04Z")

</div>

On Thu, May 27, 2010 at 10:35 PM, jhaagmans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > We have our e-mail subjects stored in I18n locale files. For the  
> > > English version of the website, we had no problem, but now we’re  
> > > translating to German, which uses a lot of symbols like ü and  
> > > Ü for example. We store them as character codes in the YAML  
> > > files,

> Because the subject lines are used in our website as well. xHTML  
> strict needs our “strange” characters to be character codes.

? What makes you think that? Or to put it another way: no, it doesn’t  
🙂

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [May 28, 2010, 8:52pm UTC](https://www.ruby-forum.com/t/html-character-codes-in-actionmailer-subject/189257/7 "2010-05-28T20:52:25Z")

</div>

Jaap H. wrote:

> Let me put in another way: we have multiple people updating the  
> language strings in the YAML files. For people working on OS X, the  
> characters will show up as squares on Linux and vice versa. I only  
> control one of these systems. How would you approach this?

Put the UTF-8 characters in the files. Make sure everyone’s editor is  
set to UTF-8.

> Our  
> approach has worked for some time now this way

It’s the wrong approach. You should apply any necessary escaping on  
output. As you’ve discovered, pre-escaped data is unusable if you’re  
generating multiple formats.

> and we only have  
> problems with ActionMailer subjects.

No, you’ll have problems with anything that isn’t HTML. So…do it  
right. Store the actual characters. Let the renderer escape characters  
on output. This is the correct and flexible approach.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
