title: Dynamically generate javascript in php or do ajax for multilanguage interface?
body: <p>I have to implement a webapp interface in several different foreign languages. I find that the jquery functions I am writing depend on what language is being implemented. For example:</p>
  
  <pre><code>    &lt;?php 
  require 'nl.php';
  /*
  if(isset($_SESSION['lang'])){
      $lang = $_SESSION['lang'];
      if(!empty($lang)){
          if($lang == 'en'){
              require 'en.php';
          }else if($lang = 'nl'){
              require 'nl.php';
          }
      }
  }
  */
  
  
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;textarea id = "notes"&gt;&lt;?php echo $string_lib['ENTER_NOTES'];?&gt;&lt;/textarea&gt;
  
          &lt;script type="text/javascript" src= "js/jquery.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src= "js/clicknotes.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So this calls for a language file that provides an array. the commented out section is just to demonstrate how I am determining what's language to send. the first require command works in its place. Now here are the language files.</p>
  
  <p>nl.php:</p>
  
  <pre><code>&lt;?php 
  $string_lib = array(
      'ENTER_NOTES' =&gt; 'Vul hier uw notities.',
      'ENTER_PASSWORD' =&gt; 'Vul hier uw wachtwoord in.',
  );
  </code></pre>
  
  <p>and en.php</p>
  
  <pre><code>&lt;?php 
  $string_lib = array(
      'ENTER_NOTES' =&gt; 'Enter your notes here.',
      'ENTER_PASSWORD' =&gt; 'Enter your password here.',
  );
  
  
  ?&gt;
  </code></pre>
  
  <p>So now, problems arise when I start doing certain things in javascript, like this, clicknotes.js:</p>
  
  <pre><code>$(window).load(function(){
      $(document).ready(function(){
          $('#notes').focusin(function(){
              if($(this).text() == 'Enter your notes here.'){
                  $(this).text('');
              }
              //alert($(this).text());
          });
      });
  });
  </code></pre>
  
  <p>So I either have to dynamically generate the javascript with php using the same method I used for the html, like this: </p>
  
  <pre><code>&lt;?php 
  header('Content-type: text/javascript');
  ?&gt;
  
  $(window).load(function(){
      $(document).ready(function(){
          $('#notes').focusin(function(){
              if($(this).text() == '&lt;?php echo $string_lib['ENTER_NOTES'];?&gt;'){
                  $(this).text('');
              }
              //alert($(this).text());
          });
      });
  });
  </code></pre>
  
  <p>or I have to send the equivalent arrays in javascript and call those variables in javascript,i.e. if($(this)).text() == string_lib['nl']['ENTER_NOTES']). OR I was thinking I could do an ajax request to get the arrays i need.</p>
  
  <p>So, which of these methods would you say is best for maintainability and ease of modification?</p>