Thanks a lot for your replies. It is not so clear for me for the moment.
I'm on Tapestry 5.1.
In all the 'tml' pages there are calls to some js functions which all are
in separate js files, like that, for example:
-----------------------------------------------------------------------------------------
script type="text/javascript">
                                loadSomeJSFunction();
                            </script>
-----------------------------------------------------------------------------------------

In all those js files all the messages are hard-coded. The question is how
to translate them? I believde that there was a way to pass a translates
variable or parameter to the js function, smth like that:

-----------------------------------------------------------------------------------------
script type="text/javascript">
                                var msgStrings = {
                                    msg1 :
'${message:js.error.password.not_given}',
                                    msg2 :
'${js.error.no_confirmed_password}',
                                    msg3 :
'${js.error.password_not_matched}',
                                    msg4 : '${js.error.email.not_given}',
                                    msg5 : '${js.error.email.wrong}'
                                  };
                                loadSomeJSFunction(msgStrings);
                            </script>
-----------------------------------------------------------------------------------------
And then in the js file just use them:
-----------------------------------------------------------------------------------------
function   loadSomeJSFunction(msgStrings) {
jQuery('#forgottenPassLink').click(function(event){
        event.preventDefault();
        var error = false;
        var email = jQuery('#email');
        var emailVal = email.val();
        var emailError = jQuery('#email-error');

        if (!emailVal) {
            error = true;
            email.addClass('error');
            emailError.html(msgStrings.msg4);
            emailError.show();
        }
}
...
loadSomeJSFunction(msgStrings);

Not sure it will work.

On Thu, Dec 22, 2011 at 12:52 PM, Christian Köberl <
tapestry.christian.koeb...@gmail.com> wrote:

> 2011-12-22 12:31, Sergueï Cambour:
> > Is it possible to translate some javascript popup mesages by injection
> the
> > translated values from a 'tml' page into javascript function which is in
> a
> > separate js file?
>
> There are two options to localize your JavaScript:
> 1. add messages in the initializer call
>   this is what Tapestry's DateField does - look in DateFieldStack
> 2. create separate asset for localized part and @Import it
>   so, you'll have mylibloc.js and mylibloc_de.js and in your
>   component class you do @Import(library={"mylib.js", "mylibloc.js"})
>
> > Thanks
> You're welcome :)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to