home
features
quick start
download
documentation
thymol files
configuration
message resources
control parameters
expression objects
thymol types
thymol API
thymol extensions
examples
sessions
say-hello
stsm example
with-dialect
extrathyme
petclinic
news
credits
user forum
issues
browser constraints
other known issues
create new issue
thymeleaf

thymoljs

thMessages

You may use a JavaScript structure called thMessages to define message values for use in templates:

        var thMessages = [
           ...
            ["welcome",          "Welcome to Thymeleaf (with Thymol)!"],
           ...
        ];

and refer to messages so defined by:

        <h2 th:text="#{welcome}">Welcome!</h2>

If you include parameter place-holders in your messages, you can control message content in the usual way.

For example, if you define:

        var thMessages = [
           ...
            ["msg07",    "We went to {1} to meet with {0} and share some {2}."]
           ...
        ];

        var thVars = [
           ...
            ["var08",    "#['Marie-Antoinette','France','cake']"],                                                           
            ["var09",    "#['Wallace','62 West Wallaby Street','cheese']"],                                                           
            ["var10",    "#['Mr. C. Monster','Sesame Street','cookies']"],
           ...
        ];

and refer to these messages in a template, parameterised correctly:

        <span th:text="${#messages.msgOrNullWithParams('msg07',var08)}">Some text</span><br/>
        <span th:text="${#messages.msgOrNullWithParams('msg07',var09)}">Some text</span><br/>
        <span th:text="${#messages.msgOrNullWithParams('msg07',var10)}">Some text</span><br/>

The result should be something like this:

        We went to France to meet with Marie-Antoinette and share some cake.
        We went to 62 West Wallaby Street to meet with Wallace and share some cheese.
        We went to Sesame Street to meet with Mr. C. Monster and share some cookies.    

locales

Thymol 2.0 introduces support for locales in message processing. Adding a group of messages to be used for a specific locale is simple, all you need to do is add a thMessages assignment with the given locale as it's array specifier.

For example, if you have a message group like this:

        var thMessages = [
                  ["msg01",    "Hello!"],
                  ["msg02",    "Hello {0}!"],
                  ["msg03",    "Hello {0}, welcome to planet {1}!"],
                  ["msg04",    "Hello {0}, good evening and welcome to planet {1}!"]
          ];

You can easily add US specific variants like this:

        thMessages["en_US"] = [
                  ["msg01",    "Howdy!"],
                  ["msg02",    "Howdy {0}!"],
                  ["msg03",    "Howdy {0}, welcome to planet {1}!"]            
          ];