mnd
mnd

Reputation: 2789

grails i18n line break

Using the Grails internationalization messages.properties I'm trying to create a multi-line message, but cannot seem to find a way to create a new line without using the <br> element, and I'd prefer to keep presentation logic out of the message. I've tried using "\n" but that doesn't get rendered.

I know I can use multiple messages "message.1=...", "message.2=...", but that doesn't seem as clean either.

Here's what I'd like to be able to do:

messages.properties

helptext=First Line\nSecond Line\nThird Line

page.gsp

<g.message code="helptext"/>

result:

First Line
Second Line
Third Line

Everything I've found either says to use <br> element, or do a replaceAll on \n, but I was hoping to not have to use extra processing to handle this.

Upvotes: 3

Views: 12206

Answers (3)

Serpent
Serpent

Reputation: 31

For me (i18n message properties in Grails 2.0 project) worked following line:

property = Line1\\nLine2\\nLine3

HTML tag BR worked also fine if displayed on HTML page, but was not any good for me, because I in my case this text needed to be a text string not HTML.

Upvotes: 3

Jim Sosa
Jim Sosa

Reputation: 628

You could write a custom tag that converts \n into br tags as well. It would just need to call the messageSource bean and parse the results. Thus your messages would not have to be HTML-specific

Upvotes: 2

dmahapatro
dmahapatro

Reputation: 50245

I think you have to use <br> in the message directly.

//messages.properties
helptext=First Line<br>Second Line<br>Third Line

//Gsp
<p><g:message code="helptext"/><p>

\ gives the ability to break the line in the properties file but renders as a single line in view.

Upvotes: 7

Related Questions