Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Note: That's not a direct answer for your problem, just suggestion for other approach</em></p> <p>You don't need to use Play's controllers at all instead you can use pure JS files placed in public assets. Let's say that you have 2 languages, one of them is default (let's assume that's English) in such case all you need to is just declare a object with translated labels and some getter ie:</p> <p><strong>/public/i18n/messages.js</strong></p> <pre><code>var messages_default = { 'save': 'Save', 'delete': 'Delete', 'warning': 'You can\'t do that' } function jsMessage(key) { var translated = messages[key]; if (typeof translated === "undefined") { translated = messages_default[key]; if (typeof translated === "undefined") { translated = key; } } return translated; } </code></pre> <p>so you can create a new file for each language and only add translations to it (note: without <code>_default</code> suffix)</p> <p><strong>/public/i18n/messages_de.js</strong> (<em>used Google translator for the 'translations, don't blame me ;)</em>):</p> <pre><code>var messages = { 'save': 'Sparen', 'delete': 'Löschen', 'warning': 'Sie können nicht tun' } </code></pre> <p>in Play's localization file (for non default languages only! <code>conf/messages.de</code> in this case) add a label for path of additional language JS file, ie:</p> <pre><code>add_i18n = i18n/messages_de.js </code></pre> <p>So finally you can include it in German version or skip in default lang with simple condition (remember that for non existing labels Play's <code>Messages</code> returns the key)</p> <pre><code>&lt;script src='@routes.Assets.at("i18n/messages_default.js")'&gt;&lt;/script&gt; @if(Messages("add_i18n") != "add_i18n")){ &lt;script src='@routes.Assets.at(Messages("add_i18n"))'&gt;&lt;/script&gt; } </code></pre> <p>So finally you can use it in JS like:</p> <pre><code>&lt;script&gt; alert( jsMessage('warning') ); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload