Mike Cenker
Mike Cenker

Reputation: 125

Use non-breaking space in Symfony translation

I am trying to use a non-breaking space character   in a translation.

# messages.cs.yml
"City near river": "Město u řeky"

However, the non-breaking space character is escaped when translating in template.

{{ 'City near river'|trans }} # prints "Město u řeky"

Is there any way how to make this work?

Upvotes: 3

Views: 2474

Answers (2)

Mike Cenker
Mike Cenker

Reputation: 125

I just found a solution using Unicode character:

# messages.cs.yml
"City near river": "Město u\xA0řeky"

Upvotes: 2

Jakub Matczak
Jakub Matczak

Reputation: 15656

You may try to add raw filter like:

{{ 'City near river'|trans|raw }}

This will prevent Twig from automatic escaping.

Also I think that it would be better to prevent breaking string in CSS instead of putting a   there.

You can achieve that with CSS rule:

white-space:nowrap;

assigned to the element containing translated string.

This way you will get more flexible translations as you may not want to get this html entity every time you use this string.

Upvotes: 2

Related Questions