messages.properties to javascript object

classic Classic list List threaded Threaded
4 messages Options
Raf
Reply | Threaded
Open this post in threaded view
|

messages.properties to javascript object

Raf
from thymeleaf template
can I convert my entire messages.properties, #{...}, file into a javascript object

example
# messages.properties file
my.message = message
my.message.label = Hello
# end messages.properties file


<script th:inline="javascript"> /* JSON */ window.messagesProperties = #{...}; /* expected ouput: window.messagesProperties = { 'my.message': 'message', 'my.message.label': 'Hello' }; */ </script>
Reply | Threaded
Open this post in threaded view
|

Re: messages.properties to javascript object

Emanuel
Administrator
I think if you just throw the Properties object into the template and surround it with the usual JavaScript inlining directives, then you'll get a JavaScript object out of it because Properties extends Hashtable which is an instance of Map, and Thymeleaf's Map writer prints out:

{
  [key]: [value],
  (repeat for every key/value pair)
}

For a map.
Raf
Reply | Threaded
Open this post in threaded view
|

Re: messages.properties to javascript object

Raf
I am not understanding your response

If this is the recommendation

{
  'my.message': /*[[#{my.message}]]*/"",
  'my.message.label': /*[[#{my.message.label}]]*/""
}

Where those weren't generated but manually typed out, that's not what I am looking for.

If I can iterate through all my properties like

messageProperties:{
<th:block th:each="property,label : ${#messages}" th:inline="text">
  '[[${property}]]': '[[${label}]]',
</th:block>
}

That would be good. but that doesn't work
Reply | Threaded
Open this post in threaded view
|

Re: messages.properties to javascript object

junior.sousa
Did you find a better solution for this case?