Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access messages in a JavaScript template in Play! Framework?

I have a template public/js/templates/info.html:

<div class="info">
    <div class="button">&{'info.close'}</div>
    <div class="info-title"><%= title %></div>
    <div class="info-text"><%= description %></div>
</div>  

&{'info.close'} should print the "Close Info" text from messages - but in web page I see "&{'info.close'}".

This work perfectly in a html view, but it doesn't work for templates. I am using JavaScript templates as that comes with backbone.js/underscore.js.

How can I achieve this?


2 Answers

You can use the i18n tag

like image 109
mericano1 Avatar answered Nov 29 '25 03:11

mericano1


Resources in the public directory are considered static data items. They are not processed by Play through the templating engine, but instead just served up as is.

If you want to make use of dynamic data, which includes internationalised javscript files, you have a couple of options.

  1. Load the internationalised message data as JSON response from within your javascript
  2. Define the templates inside your view, rather than in a separate file
  3. Load the file via controller action as if it were any other view

Your specific requirements will determine which is the right approach for your application.

like image 27
Codemwnci Avatar answered Nov 29 '25 04:11

Codemwnci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!