title: Multilingual site with database and PHP
body: <p>I am trying to come up with an efficient way to implement language selection in my site.</p>
  
  <p>I have some flags at the top right which when clicked I want all the text to change into the selected language, where the translations are stored in my database.</p>
  
  <p>Should I do this with a parameter in the url like:</p>
  
  <pre><code>www.myside.com?lang=3
  </code></pre>
  
  <p>The only issue I have with this, is that it might things complicated as far as the way I route urls and it doesn't make the url look clean either.</p>
  
  <p>Would a better way, be to have it stored in a session and the translations are only fetched from the database when the language is changed. The translations would be kept in a session array, so users don't hit the database on every page load if you know what I mean.</p>
  
  <p>I was wondering if something like the following would be a good way of achieving what I want:</p>
  
  <pre><code>    Session::set('langarray', array(
          'id' =&gt; $languageId,
          'cake' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('cake', $languageId),
          'login' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('login', $languageId),
          'register' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('register', $languageId),
          'share' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('share', $languageId),
          'galleries' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('galleries', $languageId),
          'decorator' =&gt; $this-&gt;model-&gt;getLanguagesNavigation('decorator', $languageId),
          'find' =&gt; $this-&gt;model-&gt;getLanguagesContent('find', $languageId),
          'headertext' =&gt; $this-&gt;model-&gt;getLanguagesContent('headerText', $languageId),
      ));
  
      header('Location: ' . $_SERVER['HTTP_REFERER']);
  </code></pre>
  
  <p>and in my view:</p>
  
  <pre><code>...
  public function render($viewFile, $data = NULL) {
      if(!Session::get('langarray'))
      {
          $this-&gt;Language = new Language;
          $this-&gt;Language-&gt;setLanguage(1);
      }
      if (is_array($data)) {
          extract($data);
      }
      include Vs . $viewFile . '.php';
  }
  ...
  </code></pre>
  
  <p>Which is simply set the language to 1 (English) if the session var hasn't been set i.e. a language hasn't been picked.</p>
  
  <p>In my HTML I would just echo the corresponding element in the array to get the word:</p>
  
  <pre><code>...
  &lt;p&gt;&lt;?PHP echo $_SESSION['langarray']['headertext'];?&gt;&lt;/p&gt;
  ...
  </code></pre>
  
  <p>Is this a good method? Or is there a standard way of implementing languages into a site?</p>
  
  <hr>
  
  <p>My old site currently uses an url method like the one I mentioned (?lang=3) and the foreign variants do quite well in the SEs. I like the idea of using subdomains, but how would I get it to display the correct content on my pages based on whatever come before the first . in the url? E.g. fr. de. etc</p>