title: Language PHP array - elegant way to pass to Javascript
body: <p>I have a database with strings and which language this string belongs. A string has a unique name, which I use to identify it, and then a translation for each language.</p>
  
  <p>With PHP, I get this information from the database and store it in an associative array like:</p>
  
  <pre><code>$languages['strings']['lang']['unique_string_name'] = $translation;
  </code></pre>
  
  <p>Now, as I want my Javascript code to be translated too, I need to pass it to. I've tried doing it in JSON, but some $translation have quotes and double quotes, and it's a hell to escape and get it all correct - because escaping just escapes the whole JSON string, not only translation.</p>
  
  <p>So, what I've done is loop the whole array and echoing the $translation in a Javascript associative array again, but this time with addslashes - only the translation.</p>
  
  <p>However, if I look to the Source Code, I see 600 lines of Javascripts entries, one for each translation (of course, this has nothing strange, just simply UGLY).</p>
  
  <p>I was wondering if there's a much cleaner way of passing this translation array to my Javascript code without having to loop the PHP array and echo it to a JS variable.</p>
  
  <p>Thanks for your time and answers!</p>