Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have had the same problem, and I resolved the problem simply by using the Jquery Extend function.</p> <p>Say you define your language resources as follows:</p> <p>1) Create a resource file with the default localization, presumably defined in English. Let's call it resources.default.js</p> <pre><code>var MyApp = MyApp || {}; MyApp.resources = { One: "One", Two: "Two", Three:"Three" } </code></pre> <p>2) Define your localized resources in independent files, let's say Spanish. Call it resources.es.js</p> <pre><code>var localizedResources = { One: "Uno", Two: "Dos", Three:"Tres" } </code></pre> <p>3) On your server logic, decide that you need to include only the default translations in case of English, or if you need any other language do an include.</p> <pre><code>&lt;script src="resources.es.js"&gt; &lt;/script&gt; </code></pre> <p>4) Create your web page, and add scripts to handle your inclusion of the resources, per step 3.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; ​&lt;h1&gt;Welcome to my App&lt;/h1&gt; &lt;p&gt;​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​Welcome to this test app&lt;/p&gt; &lt;button&gt;Click me&lt;/button&gt;​ &lt;script src="resources.default.js"&gt; &lt;/script&gt; // The server decided we needed Spanish translations. &lt;script src="resources.es.js"&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; //Extend the translations into the resources object. $.extend(MyApp.resources, localizedResources); $(window).ready(function(){ $('button').click(function(){ alert(MyApp.resources.One); }); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>This should work for you. ​ EDIT: See it in action here: <a href="http://jsfiddle.net/agarcian/rrDv3/1/" rel="nofollow">http://jsfiddle.net/agarcian/rrDv3/1/</a></p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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