Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call messages.property (parametrized) value from javascript on a gsp page

I am new in grails and trying to set value from messages.property (i18n) in g:set tag on gsp and then use it in java script on the same gsp page. For example:

my messages.property should look like: operation.hello=Hello '{0}'

in the gsp there should be:

<g:set var="foo" value="${operation.hello('Patty')}" scope="page"/>

and

<g:javascript>
  alert( $foo )
</g:javascript>

not sure how to handle this.Can anyone help?

our basic intention is to use a parametrized-messages.property value from javascript.

Tried JAWR plug-in and that worked well but JAWR had other issues that we do not want in our case

like image 264
VictorGram Avatar asked Dec 13 '25 04:12

VictorGram


1 Answers

So long as you understand that all this is pocessed on the server side, I think all you need to do is use the correct syntax:

<g:set var="foo" value="${g.message(code: 'operation.hello', args: ['Patty'])}" scope="page"/>

<g:javascript>
  alert( "${foo}" );
</g:javascript>

By the time this reaches the browser, it should simply read:

<script type="text/javascript">
  alert( "Hello Patty" );
</script>
like image 179
Gregg Avatar answered Dec 15 '25 18:12

Gregg