Detecting 1st Directory if its not english
<p>I have a website where its got translated languages which are the following.</p>

<p>English, German, Spanish, French and Italian.</p>

<p>I have a select box which when selected it should change the location to the translated language.</p>

<p>the main issue I'm having is figuring out how to get the url WITHOUT the translated directory name in the url.</p>

<p>So far I have</p>

<pre><code>var curURL = $('#flagsectionurl').attr('value');
var n=curURL.split("/");        
console.log(n[1]);
</code></pre>

<p>The input#flasgectionurl picks up the current page url. So if I'm looking at </p>

<blockquote>
  <p>domain.com/de/index</p>
</blockquote>

<p>the console.log will show 'de'</p>

<p>When the select box is chosen it currently does the following</p>

<pre><code>var chosenCountry = data.selectedData.value;
window.location = "/"+chosenCountry+$('#flagsectionurl').attr('value');
</code></pre>

<p>What would be the best method to change the directory whilst retaining the current page? As this method does not work as it ends up going to domain.com/de/de/index</p>
