Grails:如何在 <g:message> 默认属性中包含 html 链接?

Chr*_*oph 3 grails internationalization

我从 Grails 开始,想要一个包含多语言内容的页面。

我开始使用工作正常的标签。但这是我想做的:

我想在文本中包含默认语言的默认文本,以避免在文件之间来回切换。

<g:message code="homepage.feature.headline1" default="This is an english text" />
Run Code Online (Sandbox Code Playgroud)

以上有效。

但现在我收到一条消息,其中应包含如下链接:

<g:message code="homepage.feature.headline1" default="This is an english text with <a href='somefile.html'>a link</a>" />
Run Code Online (Sandbox Code Playgroud)

这给了我一个例外:

org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Grails tags were not closed! [[<g:message>]] in GSP 
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现在那里添加链接?我尝试过转义 <> 括号,但仍然没有成功。我真的很想避免将这一个句子分成多个较小的句子。

谢谢克里斯托夫

Szy*_*mon 5

闭包可用于嵌套 i18n 消息。我发现当链接生成需要额外的逻辑时它很有用。

<g:message code="homepage.feature.headline1" default="This is an english text with a {0}" encodeAs="raw" args="[link(controller: 'someController', action: 'someAction') { message(code:'homepage.feature.headline1.link')}]"/>
Run Code Online (Sandbox Code Playgroud)