ADBlock is blocking some content on the site

ADBlock errore

<%= %> in grails tags using i18n-gettext

StackOverflow https://stackoverflow.com/questions/10812285


I am trying to make my grails app multi language capable. For every text I want to translate I have to do:

<%=t9n.tr(s: "Delete Filter")%>

In constrast the following will work (output "Delete Filter" as string), but i18n-gettext will not find the string to translate

${t9n.tr(s: "Delete Filter")}

so I was trying someting like

<g:link controller="user" title="<%=t9n.tr(s: 'Delete Filter')%>">foo</g:link>

The following works, but looks nasty because I need 2 lines of code:

<% the_title = t9n.tr(s: "Delete Filter")%>
<g:link controller="user" title="${the_title}">foo</g:link>

any ideas? Help appreciated

No correct solution


The problem is that gettext is not capable of parsing gsp files, the plugin configures gettext to use the PHP parser in order to recognize the strings that need to be translated. That is why <% %> will fail when inside a tag.

Sadly, there is no easy solution to this, I've used every parser in gettext but none of them are capable of do it better that the PHP one.

Edit: I'm currently working on a quick (dirty) fix.

Grails contains its own i18n mechanism. The localisation files are located under /grails-app/i18n/.

In the GSP file you can use a tag:

    <g:message code="my.key" default="My key" />

In the code you can use a method:

    message( code:'my.key' )

And in some complicated situations in GSP you can combine this:

    <g:link controller="user" title="${ message( code:'delete.filter' ) }">foo</g:link>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow