简体   繁体   中英

Grails Set Error Message From messages.properties In External JavaScript File

How can I set error message on external java script file from messages.properties file so error message will change automatically based on local or language like English, German etc.

How Can I use <g:message code="" default="" /> or ${message(code:'',default:'')} on external java script file ?

In my application I pass a model object to a javascript in the following way:

<g:javascript>
    // Scroll the page to the position of the add button clicked by the user
    jQuery(document).ready(function() {
            window.scrollBy(0, ${pageScroll}); 
        });     
</g:javascript>

In your example you can define a new variable using the tag

<g:set var="tranlsatedLabel" value="${g.message(..)}"/> 

and the you can pass it like I show above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM