Lorena Bento Lorena Bento - 1 month ago 13
Ruby Question

Insert HTML special characters in (i18n) yml

I need to insert a special character in the html file translation.
The character is a space, need it to try to solve another problem.

But it is not working. The code for that character is displayed in the subject of the email.

For this I insert these lines:

pt.yml

subjects:
...
release_auto_pause_triggered_html: "%{project_name} %{release_name} - pausa automática   disparada"


release_mailer.rb

subject = t('subjects.release_auto_pause_triggered_html', project_name: @project.name, release_name: @release.name).html_safe


But the subject of the email sent is as follows:
pausa automática disparada



  • The "'" I added just to make this post, but it would not give to see here.



I need to look like this: "pausa automática disparada"

Where am I going wrong?

Answer

I think I manage to do it. Try this "pausa automática\xA0disparada"

Source:

Using single-quoted scalars, you may express any value that does not contain special characters. No escaping occurs for single quoted scalars except that a pair of adjacent quotes '' is replaced with a lone single quote '.

Double-quoted is the most powerful style and the only style that can express any scalar value. Double-quoted scalars allow escaping. Using escaping sequences \x** and \u**, you may express any ASCII or Unicode character.

And here I found the necessary code

My output is:

# YML
title: "Title \xA0 aaa"
# console
I18n.t('title')
=> "Title   aaa"
Comments