title: How do I feed terms from a gettext dictionary into JavaScript?
body: <p>I'm trying to develop a website with php and javascript (jquery) that supports multiple languages. I'm trying to obtain something that is:</p>
  
  <ul>
  <li>Efficient: I need to reduce as much as possible the backend processing for this operation.</li>
  <li>Expandable: it must be easy and practical adding new strings to the translations</li>
  </ul>
  
  <p>The problem is: my javascript code is generating dynamically various elements in the DOM and needs to print some strings that are in the language files.</p>
  
  <p>My actual solution is, using <a href="http://it2.php.net/gettext" rel="nofollow">gettext</a> in php, to print in the document the strings that have to be used by javascript:</p>
  
  <pre><code>&lt;?php
  ... some kind of gettext initialization ...
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;?php echo _("My page Title"); ?&gt;&lt;/title&gt;
      ...
  &lt;/head&gt;
  &lt;body&gt;
  
      ...
  
      &lt;script type="text/javascript"&gt;
          var LANG = {
              "string1" : "&lt;?php echo _("string1"); ?&gt;",
              "string2" : "&lt;?php echo _("string2"); ?&gt;",
              "string3" : "&lt;?php echo _("string3"); ?&gt;",
              ...
          };
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then I'm accessing to the <code>LANG</code> in my js sources, but I don't think that this is the best solution...</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>What is the correct approach to apply a translations to a javascript file, using the same "database" of php?</li>
  <li>How efficient is <code>gettext</code> library? It could be useful to implement some form of caching mechanism on the generated pages?</li>
  </ul>